I want to import an array (imageArray[]) that is being populated by another JavaScript file (imageUploadDisplay.js) into another JavaScript file function (postInfoAndImages.js). Below is my imageUploadDisplay.js function that I tried to use.
// In my imageUploadDisplay.js
var imageList = [];
function myImageList() {
return imageList;
}
As explained by others I use the following jQuery to import imageUploadDisplay.js into the JavaScript postInfoAndImages.js:
// In my postInfoAndImages.js
var imageList = [];
$.getScript('imageUploadDisplay.js', function () {
// Script is now loaded and executed.
alert("Script loaded, but not necessarily executed.");
imageList = myImageList(); // Picture array
console(imageList);
});
imageUploadDisplay.jsinto a function created inpostInfoAndImages.jspostInfoAndImages.js, contrary to what you are thinking. You are simply executing a piece of code which is injecting another script to the document itself, and not topostInfoAndImages.js, thus it should already be globally accessed, depending on what's inside the injected script.