Reputation: 4303
I have an ajax script that downloads pulls data of the server, which contains some javascript code. The response is placed into the innerHTML
of a target div. After that, the script scans through the div that contains the new html for any script tags.
This is the point where it starts to stop working. Initially, I tried to add each script to the head, which it did successfully, but didn't load any scripts referenced externally (i.e. src="test.js"), nor run any of the new code.
My next attempt was to run through each script item, then use eval
on script.text
, which successfully executed the script that was parsed, but still didn't load any externally referenced scripts.
Does anyone have any suggestions of what to try next?
Upvotes: 1
Views: 1460
Reputation: 2243
I you use jQuery, you could use this call:
$.getScript("test.js", function(data, textStatus, jqxhr) {
console.log(data); //data returned
});
You can find documentation here: http://api.jquery.com/jQuery.getScript/
Or with Mootools:
Asset.javascript("test.js");
You can find documentation here: http://mootools.net/docs/more/Utilities/Assets
Upvotes: 1