Skip to content

Instantly share code, notes, and snippets.

@adamlwgriffiths
Last active November 11, 2015 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamlwgriffiths/1744d720fe1a4144f114 to your computer and use it in GitHub Desktop.
Save adamlwgriffiths/1744d720fe1a4144f114 to your computer and use it in GitHub Desktop.
var loadScript = function(url, callback) {
/*
JavaScript that will load the jQuery library on Google's CDN.
We recommend this code: http://snipplr.com/view/18756/loadscript/.
Once the jQuery library is loaded, the function passed as argument,
callback, will be executed.
*/
var script = document.createElement("script");
script.type = "text/javascript";
if (script.readyState) { //IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
};
var jqueryLoaded = function($) {
$.ajax(
'/admin/metafields.json', {
dataType: 'json',
complete: function(jqXHR, textStatus) {
j = jqXHR.responseJSON;
console.log(j);
}
});
};
if ((typeof jQuery === 'undefined') || (parseFloat(jQuery.fn.jquery) < 1.7)) {
loadScript('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', function(){
jQuery191 = jQuery.noConflict(true);
jqueryLoaded(jQuery191);
});
} else {
jqueryLoaded(jQuery);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment