I am loading a few scripts using JavaScript $ajax in an async manner. I need them to load in a certain order but at the moment it's random.
The code I have is:
loadScripts();
function loadScripts() {
getBootStrapperScript(function (callback) {
alert('bootStrapper loaded');
})
getXMLScript(function (callback) {
alert('xml script loaded');
});
getFormScript(function (callback) {
alert('form script loaded');
});
}
function getBootStrapperScript(callback) {
$.ajax({
url: "http://localhost/eSales/scripts/bootStrapper.js",
dataType: "script"
}).done(callback);
}
function getXMLScript(callback) {
$.ajax({
url: "http://localhost/eSales/scripts/LoadXML.js",
dataType: "script"
}).done(callback);
}
function getFormScript(callback) {
$.ajax({
url: "http://localhost/eSales/scripts/LoadForm.js",
dataType: "script"
}).done(callback);
}
You can see it running in this jsFIddle
Is there a nice and elegant way of ensuring the scripts load in the order they are defined?