在 QML JavaScript 中使用 XMLHttpRequest 时遇到问题
在 QML 和 JavaScript 中使用 XMLHttpRequest 时遇到问题。
我通过 QML 按钮单击调用 JavaScript 函数,在该 JavaScript 中,我将 XMLHttpRequest
发送到服务器。但是,当我发送请求时,我会立即在函数中回调(我已使用 onreadystatechange
属性拒绝了该函数),因为 req.readyState == XMLHttpRequest.DONE
但 req.status 为“0”。
通常我们得到的 readyState
如下:
XMLHttpRequest.UNSENT = 0;
XMLHttpRequest.OPENED = 1;
XMLHttpRequest.HEADERS_RECEIVED = 2;
XMLHttpRequest.LOADING = 3;
and then
XMLHttpRequest.DONE = 4;
在完成状态下,我们检查请求状态,该状态应该是 200。
什么会导致这种行为。
这是 QT JavaScript 解释器的问题吗?
我很困惑,
谢谢。
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 function (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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否碰巧在后端使用带有自签名证书的 HTTPS 连接?如果是,请尝试使用纯 HTTP(或使用有效的 SSL 证书) - 几天前使用自签名证书也遇到了类似的问题。
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.
我不能说是否QT解释器有问题,但可能是你的请求有问题。
req.readyState == XMLHttpRequest.DONE
并不意味着请求成功;即使出现错误,您也会得到它,请参阅此源中的DONE。从状态属性:
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.From the status attribute: