I'm mostly a newbie when it comes to JS I just google how to do stuff as I need to. I got this code to work based on googling, but I'm just trying to figure out exactly whta's going on, because the order in which it executes is odd and I just want to make sure I add in the proper checks and error handling but I need to understand it better first.
The part I don't quite understand is how those onprogress and onload parts work, and what does the =function() part do?
I understand that this is basically non blocking sockets, but just trying to figure out how it's executing and in what order. Are they spawning different threads?
Basically the console output for one run (this runs in a loop) is as follows :
The fact that IP and Load show AFTER RA End seems to indicate this is running in some kind of thread. Is that what is happening?
Essentially I need to understand this better so I can add in the proper checks to make sure if there are network delays the loop won't try to execute twice when it's already in progress.
Code:
function RetrieveAlarms()
{
const Http = new XMLHttpRequest();
const url="index.php?mod=getalms";
console.log("RA");
var xhr = new XMLHttpRequest();
SetMsg("Updating...");
xhr.open("GET", url, true);
xhr.onprogress = function ()
{
console.log("IP");
SetMsg("Updating......");
};
xhr.onload = function ()
{
console.log("load");
ProcessAlarms(xhr.responseText);
SetMsg("Last Updated: " + FormatDate(1234));
};
xhr.send(null);
console.log("RA end");
}
The part I don't quite understand is how those onprogress and onload parts work, and what does the =function() part do?
I understand that this is basically non blocking sockets, but just trying to figure out how it's executing and in what order. Are they spawning different threads?
Basically the console output for one run (this runs in a loop) is as follows :
Code:
RA
RA end
IP
Load
The fact that IP and Load show AFTER RA End seems to indicate this is running in some kind of thread. Is that what is happening?
Essentially I need to understand this better so I can add in the proper checks to make sure if there are network delays the loop won't try to execute twice when it's already in progress.
