I am making a website that requires for it to read a value from a .txt file(which for testing purposes was set to "8080") to then store that value into a global variable. Here is the code that I'm having issues with:
var portTxtFile = "/assets/port.txt";
var portTxtData;
jQuery.get(portTxtFile, function(data) {
console.log(data);
portTxtData = data;
});
console.log(portTxtData);
The console logs were added to test if the variable was really being set. Here are the results of the console logs:the console
For some reason, the console is logging the console.log(portTxtData) outside of the jQuery.get function before the console.log(data) that's inside the function. And the variable "portTxtData" is not being set.
I need help setting the variable "portTxtData" to "data" from the "jQuery.get" function.