QML does not see httprequest.readyState
-
hello...
so scenario:property var xmlrequest = new XMLHttpRequest() function triggerRequest() { xmlrequest.abort(); // cancel old call if any xmlrequest.onreadystatechange() { console.log("readystateChanged to:", xmlrequest.readyState); // properly print 1, then 2, then 3, then 4 } MODEL.feed_xmlhttp.onload = function() { console.log("loaded, so status should be 4", xmlrequest.readyState); // properly debugs 4 } xmlrequest.open("GET", some_url, true); xmlrequest.send(); } function doSomething() { console.log("triggered"); } property bool checkIfIsFinishedProcessing: xmlrequest.readyState onCheckIfIsFinishedProcessingChanged: if (xmlrequest.readyState == 4) { doSomething(); } // this does nothing (XMLHttpRequest.DONE also does not work, === operator for both (4 and DONE) also dont) onCheckIfIsFinishedProcessingChanged: console.log(typeof xmlrequest.readyState, xmlrequest.readyState) // properly debugs "number" as type, and then 1, 2, 3, 4 as it changes...
so what do I do wrong here?
-
Please read the documentation about the
XMLHttpRequest
type.The important part is:
Assign a callback function to the onreadystatechange signal handler.More specifically,
readyState
doesn't have a change signal. Furthermore, the (redundant) binding tocheckIfIsFinishedProcessing
is crippled. If it would work at all, it would bind an enumeration to a boolean. Comparing the result to the int value 4, is also not a recommended practive. Better use the enum valueDone
for better code readability. -
I am not sure, what your question exactly means.
You have to implement a function and register it as the callback function for state changes.
Totally up to you, what that function does/triggers/changes/debugs.