Yes, I am aware that there are many, many, many posts about Javascript variables and how to properly access them and their scope, etc. However, I still can't figure out my problem, even after spending a couple hours trying to fix it with multiple StackOverflow posts and other articles. Here is my code, for let's say part2.js, so far:
var dataval = "";
callCgiFile().then(function(data) {
dataval = data;
alert(dataval); //ALERTS data PROPERLY
});
alert(dataval); //DOESNT ALERT data at all
I basically have another Javascript file, say part1.js, such is as follows:
function callCgiFile() {
return $.get('somecgifile.cgi');
}
and am calling that function within my part2.js file, as is shown. I am accessing the data from the CGI file and am trying to access it outside of the function, however, it is not working at all. I have honestly read many other similar questions about this problem but none of them have worked out for me. Is there anything I can do to fix my issue?? Please let me know! Thank you so much!