1

我正在学习 Qooxdoo 框架,并且正在尝试使其与小型 Django Web 服务一起使用。Django webservice 只返回 JSON 数据,如下所示:

{ "name": "Football", "description": "The most popular sport." }

然后我使用以下代码查询该网址:

var req = new qx.io.remote.Request(url, "GET", "application/json");
req.toggleCrossDomain();

req.addListener("completed", function(e) {
                 alert(e.getContent());
                    });
req.send();

不幸的是,当我执行代码时,我得到了意外的令牌错误,然后请求超时。

Uncaught SyntaxError: Unexpected token :
Native.js:91013011 qx.io.remote.RequestQueue[246]: Timeout: transport 248
Native.js:91013011 qx.io.remote.RequestQueue[246]: 5036ms > 5000ms
Native.js:91013013 qx.io.remote.Exchange[248]: Timeout: implementation 249

JSLint 报告这是一个有效的 JSON,所以我想知道为什么 Qooxdoo 没有正确解析它。

4

2 回答 2

5

问题可能出在这一行:

req.toggleCrossDomain();

crossDomain 默认为 false,因此 toggleCrossDomain 将其设置为 true。这迫使 qx.io.remote.Request 使用脚本传输,它不像常规 XMLHttpRequest 那样工作:请求需要包含一个 id,而服务器的响应必须使用相同的 id 并将实际响应包装在调用中到 qx.io.remote.transport.Script._requestFinished()。这在 qx.io.remote 包的文档中有更详细的解释:

http://demo.qooxdoo.org/current/apiviewer/#qx.io.remote

于 2010-05-25T12:30:36.837 回答
0

您的请求正在超时。网址对吗?连接到它是否存在防火墙问题?基本上,您的代码没有收到您期望的 JSON,而是收到了超时错误。

于 2010-05-24T11:39:51.903 回答