开发者

Facing Issue while using XMLHttpRequest with QML JavaScript

开发者 https://www.devze.com 2023-04-06 22:19 出处:网络
Facing Issue while using XMLHttpRequest with QML and JavaScript. I am calling JavaScript Function from a QML button click, In that JavaScript I am sending XMLHttpRequest to an server. But when I send

Facing Issue while using XMLHttpRequest with QML and JavaScript.

I am calling JavaScript Function from a QML button click, In that JavaScript I am sending XMLHttpRequest to an server. But when I send the request I get immediate call back in the funct开发者_JS百科ion (which I have resisted using onreadystatechange property) as req.readyState == XMLHttpRequest.DONE but req.status is '0'.

Usually we get readyState as follows:

XMLHttpRequest.UNSENT = 0; 
XMLHttpRequest.OPENED = 1; 
XMLHttpRequest.HEADERS_RECEIVED = 2; 
XMLHttpRequest.LOADING = 3; 
and then
XMLHttpRequest.DONE = 4;  

and in done state we check for request status which should be 200.

What can cause this type of behavior.

Is this an problem with QT JavaScript Interpreter?

I am stuck with this

Thanks.


I can't say whether there is a problem with the QT interpreter, but it may be a problem with your request. req.readyState == XMLHttpRequest.DONE does not imply that the request was a success; you will get it even on an error, see DONE in this source.

DONE (numeric value 4)

The data transfer has been completed or something went wrong during the transfer (e.g. infinite redirects).

[...]

The DONE state has an associated error flag that indicates some type of network error or abortion. It can be either true or false and has an initial value of false.

From the status attribute:

The status attribute must return the result of running these steps:

If the state is UNSENT or OPENED return 0 and terminate these steps.

If the error flag is true return 0 and terminate these steps.

Return the HTTP status code.


Do you happen to use HTTPS connection with a self-signed certificate in the backend? If yes, try with plain HTTP instead (or with a valid SSL cert) - had a similar kind of problem few days ago with a self-signed cert.

0

精彩评论

暂无评论...
验证码 换一张
取 消