Qooxdoo REST JSON 请求问题 - 意外令牌然后超时
我正在学习 Qooxdoo 框架,并尝试使其与小型 Django Web 服务一起使用。 Django webservice 只是返回如下 JSON 数据:
{ "name": "Football", "description": "The most popular sport." }
然后我使用以下代码来查询该 url:
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 不能正确解析它。
I am learning Qooxdoo framework and I am trying to make it work with a small Django web service. Django webservice just returns JSON data like this:
{ "name": "Football", "description": "The most popular sport." }
Then I use the following code to query that url:
var req = new qx.io.remote.Request(url, "GET", "application/json");
req.toggleCrossDomain();
req.addListener("completed", function(e) {
alert(e.getContent());
});
req.send();
Unfortunately when I execute the code I get unexpected token error and then request timeouts.
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 reports that this is a valid JSON, so I wonder why Qooxdoo doesn't parse it correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能出在这一行:
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
The problem is probably with this line:
req.toggleCrossDomain();
crossDomain is false by default, so toggleCrossDomain sets it to true. This forces qx.io.remote.Request to use the script transport, which doesn't work like a regular XMLHttpRequest: The request needs to contain an id, while the server's response must use the same id and wrap the actual response in a call to qx.io.remote.transport.Script._requestFinished(). This is explained in greater detail in the documentation for the qx.io.remote package:
http://demo.qooxdoo.org/current/apiviewer/#qx.io.remote
您的请求已超时。网址对吗?连接到它时是否存在防火墙问题?基本上,您的代码没有收到您期望的 JSON,而是收到超时错误。
Your request is timing out. Is the URL right? Are there firewall issues connecting to it? Basically, your code is not receiving the JSON you expect, but is instead receiving a timeout error.