在 QML JavaScript 中使用 XMLHttpRequest 时遇到问题

发布于 2024-12-06 03:23:46 字数 652 浏览 3 评论 0原文

在 QML 和 JavaScript 中使用 XMLHttpRequest 时遇到问题。
我通过 QML 按钮单击调用 JavaScript 函数,在该 JavaScript 中,我将 XMLHttpRequest 发送到服务器。但是,当我发送请求时,我会立即在函数中回调(我已使用 onreadystatechange 属性拒绝了该函数),因为 req.readyState == XMLHttpRequest.DONEreq.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖风昔人 2024-12-13 03:23:47

您是否碰巧在后端使用带有自签名证书的 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.

风铃鹿 2024-12-13 03:23:46

我不能说是否QT解释器有问题,但可能是你的请求有问题。 req.readyState == XMLHttpRequest.DONE并不意味着请求成功;即使出现错误,您也会得到它,请参阅此源中的DONE

完成(数值4)

数据传输已完成或传输过程中出现问题(例如
无限重定向)。

[...]

DONE 状态有一个关联的错误标志,指示某种类型的网络错误或中止。它可以是 true 或 false,并且初始值为 false。

状态属性

状态属性必须返回运行这些步骤的结果:

如果状态为 UNSENT 或 OPENED,则返回 0 并终止这些步骤。

如果错误标志为 true,则返回 0 并终止这些步骤。

返回 HTTP 状态代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文