[SOLVED]multiple XMLHttpRequest fires in random order
-
I have 3 different files opened, using XMLHttpRequest in different functions, that parses data. It seems, that they are finishing reading of files in different order, than associated functions, that are called with XMLHttpRequest in them. It seems, that biggest of files is finished last no matter what order it takes in calls.
It is crucial to complete parsing data of first three, before starting to parse 4th, as it uses and modifies global extracted data from first three files. Initially it worked - sometimes I had to restart call, but there was a random chance, that all data was read before it was modified, so I thought that it was because of bad connection, but now it does not read biggest file in time at all. The biggest file is read AFTER all other functions - even the ones, that were written in code after the biggest file reader.
Sizes of files for comparision(in bytes):
- 8 003
- 6 329 - this finishes after first, because there is more parsing involved, than in first file
- 139 219 - takes a lot longer than couple of seconds
- 32 693 - just started to process and should be read last.
-
The idea was to use JavaScript to the timed delays, but apparently after consulting resources about QML it seems, that the only way is using QML events and call 4th function alone after first three are done.
Anyway, to beginners of JavaSript no example mentions this XMLHttpRequest nonreliable behaviour, but for sure - in most cases it is required to read more than just one file and this behaviour is weird for human logic, as it is imagined that all those XMLHttpRequest are run in sequence - not all at once, as it really happens.
-
The file loading function that I wanted looks like this(allows to load only one file after another):
Qt.include("Script.js") //scripts are in plain JavaScript
function loadFile(processFunc, fileName)
{var request = new XMLHttpRequest() request.open('GET', fileName) request.onreadystatechange = function(event) { if (request.readyState == XMLHttpRequest.DONE) { WorkerScript.sendMessage( {response: processFunc(request.responseText)} ); } } request.send();
}@