Mohmmad Ebrahimi Aval Mohmmad Ebrahimi Aval - 1 year ago 198
Ajax Question

how to get .js file context with jQuery $.ajax without execute when receive

when get *.js file by $.ajax, Scripts are executed after receive!

how to get and executed when i want?
how to destroy this scripts when i want?

Answer Source

Not sure for jQuery, but you can do it using XHR method.

function getScript(b, c){
  var a = new XMLHttpRequest();'get', b, true);
  a.onreadystatechange = function(){
    a.readyState != 4 || a.status && a.status != 200 || c(a.responseText);

getScript('script.js', function(content){
    // Do whatever here
    Function(content)(); // Execute the script
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download