I have 5 different js files which I want to execute after an ajax call success response status.
What I am currently doing is :
function require(list, fn)
{
for (var i = 0; i < list.length; i++) {
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = list[i];
if (newScript.readyState){ //IE
newScript.onreadystatechange = function(){
if (newScript.readyState == "loaded" ||
newScript.readyState == "complete"){
newScript.onreadystatechange = null;
callback();
}
};
} else { //Others
newScript.onload = function(){
callback();
};
}
newScript.src = url;
headID.appendChild(newScript);
}
}
Let's say I have file1.js,file2.js,file3.js . I have a variable dca declared on file2.js which I want to use for some operations in file3.js. For that I need to load file1.js,file2.js sequentially . But unfortunately, this is not happening in the method that I am using.
Please help how to achieve this goal.
I even tried with
addEventListeners('load',function({ //some operations }));
but to no effect.
dcaa global variable ?