javascript - ZF2 jQuery datepickers not working in ajax dialogs -


some actions on zend framework 2 web application open via dialog. use method when processing action called ajax:

/**  * display content on ajax call.  * @param \zend\mvc\mvcevent $e  */ public function ondispatch(\zend\mvc\mvcevent $e) {     $app = $e->getparam('application');     $layout = $app->getmvcevent()->getviewmodel();     if($app->getrequest()->isxmlhttprequest()) {         $controller = $e->gettarget();         $controller->layout('application/ajax/ajax');         $layout->setterminal(true);     } } 

the problem datetime pickers of jquery not seem work. because html gets added dynamically page.

i think solution might modify ondispatch method re-includes of js-files. or there better way? thought adding js-files hard-coded ajax.phtml file work.

but again, know if there better approach exists, reloading js on page or something.

yeah, 1 way add scripts ajax.phtml.

something did while ago send required scripts response header:

$requiredscripts = array(     '/some/js/file.js',     '/another/js/file.js' ); $this->getresponse()->getheaders()     ->addheaderline('x-scripts: ' . json_encode($requiredscripts)); 

then in js:

// globally listen ajax-requests $(document).ajaxsuccess(function(res, status, xhr) {      var requiredscripts = xhr.getresponseheader("x-scripts");     if (requiredscripts) {         jquery.each(requiredscripts, function(index, scriptsrc) {             jquery.getscript(scriptsrc);         });     } }); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -