Archive for February, 2013

load external JavaScript from within another JS

Monday, February 25th, 2013

Of course there are many ways to do this, js loading libraries/managers,
what if you can’t get to the html though, and want to have control over all JS functions externally,
say from the JS files alone on a separate CDN… a JS ‘include’ is what we need…
since jQuery 1.8, in order to get a callback to take action in the even that the file doesn’t load,  a ton of different solutions that used to work, no longer do, and with jsonp or script type calls, the error function doesn’t even get called, here’s to trying to get one to work:

complete, success, .error, and on and on…

but no, solution:

var jqxhr = $.ajax({
url: “http:/…”,
dataType: ‘script’,
crossDomain: true,
timeout: 5000,
cache: false
})
//.done(function() { alert(“success”); })
.fail(function() { ajaxFailure(); })
//.always(function() { alert(“complete”); });

 

reference: http://api.jquery.com/jQuery.ajax/