It looks like the jQuerys evalScript function is starting you up ...
Line 543 jQuery:
function evalScript( i, elem ) { if ( elem.src ) jQuery.ajax({ url: elem.src, async: false, dataType: "script" }); else jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); if ( elem.parentNode ) elem.parentNode.removeChild( elem ); }
Here is a breakdown of what happens: The JS main page calls:
$.ajax({ url:"frag.htm", type:"GET", success:callBackFunction })
and GETs frag.htm, which contains something like this:
<html><head><script src="test.js"></script></head><body>Content</body></html>
then the callback function is called, which probably looks like this:
function callBackFunction(data){ $("#ajaxContent").html(data);
When the jQuery html (data) function is called, it "clears" the HTML by removing any script tags, and then calls evalScript on each of them. evalScript, as you can see, does not indicate "cache: true", so when it passes through the $ .ajax cache, it is zero. When the cache is null and dataType is a "script", jQuery sets cache = false.
So, to get around this problem, try the following:
function callBackFunction(data){ var tempAJAX = $.ajax; // save the original $.ajax $.ajax=function(s){ // wrap the old $.ajax so set cache to true... s.cache=true; tempAJAX(s); // call old $.ajax } $("#ajaxContent").html(data); // insert the HTML and download the <script>s $.ajax = tempAJAX; // reset $.ajax to the original. } }
Before inserting the new HTML from "frag.htm" into the main page, we intercept all calls to $ .ajax, change the object by turning on cache = true, and then after loading the script, paste the HTML.
Let me know if you have any questions.