Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript file not executing after AJAX call
    text
    copied!<p>When I make an AJAX call to replace a div, the response contains a script tag pointing to an external .js file. However, I can't get the returned JS to execute. I've tried to eval() the response but that didn't work. I also tried to call a function inside the external .js file from within the onComplete callback, but this also does not work. Not sure what else to do. I'm using mootools core 1.4.5</p> <p>Main page's JS</p> <pre><code>window.addEvent('domready', function(){ function ajaxfunc(i) { return function(e){ e.stop(); var requestData = new Request({ url: 'blah.php?cat=' + i, evalScripts: true, evalResponse: true, onComplete: function(response){ $('rt-main').set('html', response); } }); requestData.send(); }; } var total = $('cat_table').getChildren('div').length; for(var i=1; i&lt;=total; i++) { $('catClick'+i).addEvent('click', ajaxfunc(i)); } }); </code></pre> <p>The returned HTML</p> <pre><code>&lt;script src="listings.js" type="text/javascript"&gt;&lt;/script&gt; ...(other markup, etc) </code></pre> <p>And inside that listings.js file</p> <pre><code>window.addEvent('domready', function(){ function gotoItem(i) { return function(e){ e.stop(); var id= i; var requestData = new Request ({ url: 'blah.php?id='+id, onComplete: function(response){ $('rt-main').set('html', response); } }); requestData.send(); }; } $$('.itemBox').each(function(el){ el.getElement('a.itemClick').addEvent('click', gotoItem(el.id)); }); }); </code></pre> <p>The environment I'm working in is Joomla 3.1 in case that affects anything.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload