Magento: Adding a JS file to the head in an Ajax call? -


i calling controller using ajax. controller function called testaction(). works nice, function gets called. want add js header in function. approach this:

i created handle, adds js file header:

<my_handle>     <reference name="head">         <action method="addjs">             <script>somefolder/myjs.js</script>         </action>     </reference> </my_handle> 

now added code controller add handle in ajax call, this.

$layout = $this->getlayout()->getupdate(); $layout->addhandle('my_handle'); 

normally works pretty good, since ajax call, doesnt seem work (file not included after call returned). question is: how can add javascript file head in ajax call?

thanks!

since calling controller via ajax load javascript using jquery/javascript:

using jquery:

method: jquery.getscript() description: load javascript file server using http request, execute it.

see official documentation more information.

using prototype:

var head; var script;  head = $$('head')[0]; if (head) {     script = new element('script', { type: 'text/javascript', src: 'dynamic.js' });     head.appendchild(script); } 

see here additional info.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -