I am new to zend framework and as well as ajax. I want a specific action in my application.
Let say I have an action and its corresponding view. In that view I have multiple things like chart plotting, table making and other HTML things.
I want to only update the chart on drop drown change event without loading whole page again.
How can do this. Help me in this regard.
I searched a lot but can't find any thing useful.
IndexContrller
public homeAction(){
if($num==0){
//Chart Data Here
}
else if(num==1){
//Table Data Here
}
}
In short I want to update an Action portion using Ajax in ZEND Framework.
how I have implemented Ajax submission using jQuery in Zend Framework. You have to build your form like the following.
$form->setAttrib('id','div_form');
$form->addElement('submit', 'submit', array(
'label' => 'Ajax Submit',
'onclick' => "$('#div_form').load('" . "/index/home" . "', $('#div_form').serializeArray() ); return false;"
));
Add the submit like the one shown above.
return false; cancels actual submission of form.
In your IndexController.php,
public function homeAction() {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(TRUE);
//Get your form data from the params
Zend_Debug::dump($this->_getAllParams());
//Process data using your model and return appropriate messages.
echo "Your form is submitted"; // here you can render your element for display graph in view
}
Try the above and let me know if you have any issues.
hope this will sure help you.