I want to load jQuery from Google's CDN, and execute jQuery code if the request succeeded, but I can't seem to get it working right. Here's my code:
function loadjQuery(success, error) {
var xhr = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHttp');
xhr.onload = function() { success(xhr.status, xhr.readyState); }
xhr.onerror = function() { error(); }
xhr.open("GET", "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js", true);
xhr.send();
}
loadjQuery(
function(status, state) {
console.log(status) // 200
console.log(state) // 4
console.log($('body')) // Uncaught ReferenceError: $ is not defined
},
function() { setTimeout(loadjQuery, 10000); }
);
Any help would be really appreciated