Comment j'intègre Ajax avec zendframework.J'ai besoin de bons tutoriels.
1
A
Répondre
3
Mettez dans votre contrôleur
public function init()
{
$contextSwitch = $this->_helper->getHelper('contextSwitch');
$contextSwitch->addActionContext('test', 'json')
->initContext();
}
créer une action de test
public function testAction()
{
$this->view->var1 = "I'm testing";
}
Utilisez ensuite jquery pour effectuer la demande à votre avis
<script type="text/javascript">
$(document).ready(function(){
$('#display').ajaxStart(function(){
$(this).html('Loading...');
});
str = $('#test').val();
$('#link').bind('click',function(event){
event.preventDefault();
$.post(
this.href,
{ var1: str, format: 'json' },
function(data){
$('#display').html(data.var1);
},
"json"
);
});
});
</script>
<input type="text" name="test" id="test" value="just testing" />
<p>
<a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'test')); ?>" id="link">Testar</a>
</p>
<div id="display">...</div>
1
Vous pouvez utiliser quelque chose comme ça dans votre contrôleur:
public function testAction() {
// Remove all of your HTML stuff
$this->_helper->layout->disableLayout();
// PHP to create an array form database or something
// This will return the info as json. It takes care of the header and everything else!
return $this->_helper->json->sendJson(array('test'));
}
Questions connexes
- 1. Image à partir de PDF avec ZendFramework
- 2. Zendframework/PgSQL fetchAll orderby
- 3. Zendframework Routing Issue
- 4. Problème de lien Zendframework
- 5. Soumission de données dans Zendframework
- 6. CSS ne s'applique pas correctement dans ZendFramework
- 7. zendframework baseUrl voir helper dans bootstrap
- 8. Ajout bibliothèque 3ème partie à ZendFramework
- 9. ZendFramework Zend_Form_Element_File setDestination vs renommer le filtre
- 10. Implémentation d'une association contrôleur/vue efficace comme ZendFramework
- 11. Je cherche l'application Web open source qui a utilisé ZendFramework
- 12. ZendFramework - Recherche des requêtes en cours - Manière plus facile
- 13. comment insérer une image dans Db comme blob dans ZendFramework
- 14. ASP.NET Ajax avec Mono
- 15. ajax avec l'aide MVC
- 16. problème avec AJAX
- 17. ASP.Net healthMonitoring avec AJAX
- 18. jquery ajax avec servlet
- 19. avec demande AJAX
- 20. synchrone Ajax avec jQuery
- 21. appeler ruby avec ajax
- 22. rails fields_for avec ajax
- 23. solr avec jquery ajax?
- 24. JSP discuter avec ajax
- 25. Ajout d'entrées avec AJAX?
- 26. Sharepoint avec ASP.NET Ajax
- 27. problème avec ajax post
- 28. Ajax avec jQuery
- 29. Novice avec jQuery AJAX
- 30. \ n avec jquery ajax