Encountering strange behavior with JavaScript.
I am currently working on a basic example application using QT-QML and JavaScript.
Within this application, I have implemented HTTP Requests triggered by a button that sends the request through JavaScript.
Upon receiving the response from the HTTP request in the callback function, I attempt to check the state of the HTTP response in the following manner.
if( httpReq.readyState == 4 ) //Issue
{
if(httpReq.status == 200 )
{
...
I aim to verify if readyState
equals 4
(where 4 indicates completion)
However, the conditions fail to evaluate properly, always returning true regardless of the value of readyState
.
For instance, even if readyState
is 0
(0 == 4), the if statement still evaluates as TRUE which should not be the case.
What could be causing this unexpected behavior?
I have attempted the following:
1. if( parseInt(httpReq.readyState) == 4 )
2. if( Number(httpReq.readyState) == 4 )
3. if( httpReq.readyState == '4' )
The above conditions yield the same results, evaluating to TRUE regardless of the actual value of readyState
.
Could there possibly be an issue with my JavaScript Interpreter?
Thanks.
------UPDATE-----
The issue lies within having both the QML application (sending HTTP requests) and the HTTP server (serving these requests) within the same application/process. When separating the HTTP server and QML application into two distinct applications/executables, everything functions correctly. However, combining them into one executable causes problems. Combining both the HTTP server and QML application within one executable seems to disrupt the functionality of the QML JavaScript interpreter. The QML application runs in a Separate Thread before launching the Web server.