Ajax at work zend frame
I am new to Zend Frame Work. I am using $ ajaxContext = $ this -> _ helper-> getHelper ('AjaxContext'); to add action contexts. I have one Index.phtml page and all the others are ajax.phtml pages. I need to do some java script methods in ajax.phtml pages. But I haven't found a way to link to js files in the ajax.phtml pages. I tried to add them to the init and index action of the controller using $ this-> view-> headScript () -> appendFile, although I have a link added in the page source, none of the htese seem to work on the ajax content. i tried to add it to the action for the ajax page then it is not included in the source of the page. As I understand it, $ this-> view-> headScript () -> appendFile will add a file link to the layout page and ajax.phtml pages,the layout will be disabled. Is there a way that I can link to my js files in the ajax.phtml pages?
a source to share
I found two ways to solve this problem. One is that we can bind the click event for the postbacked content ajax button using the jquery.live () method. This will register the element with the DOM even if the element is missing during page load. Another way is to reload the javascript on every ajax postback success using the getScript () method. This way, all newly added items will be registered and active. if you are using jquery dialogs using variables you might have to destroy them before reloading js.
a source to share
Place this code in a publicly accessible Controller function:
public function indexController(){
$this->_helper->viewRenderer->setNoRender();
$Response = $this->getResponse();
$Response->setBody(Zend_Json::decode($foo))
->setHeader('content-type', 'application/json', true);
return null;
}
a source to share