Friends,
How I integrate Ajax with zendframework.I need some good tutorials.
Friends,
How I integrate Ajax with zendframework.I need some good tutorials.
Put this in your controller
public function init()
{
    $contextSwitch = $this->_helper->getHelper('contextSwitch');
    $contextSwitch->addActionContext('test', 'json')
                  ->initContext();
}
create a test action
public function testAction()
{
    $this->view->var1 = "I'm testing";
}
Then use jquery to perform the request in your view
<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>
Do you want to use Zend_Form, or just plain ajax?
Then you must learn how to return data in JSON, to parse it with jQuery, you can use something like this on your controller:
public function myCoolFunctionAction () {
// 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 a json script, it takes care of the header and everything else!
return $this->_helper->json->sendJson ( array( ) );
}
Then you can parse it in jqury and you are done :)
hope it helps