我的顶点团队决定使用 Qooxdoo 作为我们项目的前端。我们正在使用 NOX 为 OpenFlow Controller 开发应用程序,因此我们使用的是 NOX Web 服务框架。我无法从服务中获取数据;我知道该服务正在运行,因为如果我使用 Firefox 访问 URL,则会显示正确的数据。这是我的代码的相关部分:
var req = new qx.io.remote.Request("http://localhost/ws.v1/hello/world",
"GET", "text/plain");
req.addListener("complete", function(e) {
this.debug(e.getContent());
});
var get = new qx.ui.form.Button("get");
get.addListener("execute", function() {
alert("The button has been pressed");
req.send();
}, this);
form.addButton(get);
在 Firebug 控制台中,我在单击警报后收到此消息:
008402 qx.io.remote.Exchange: Unknown status code: 0 (4)
如果我再次按“获取”按钮,则会收到此错误:
027033 qx.io.remote.transport.XmlHttp[56]: Failed with exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: file:///home/user/qooxdoo-1.0-sdk/framework/source/class/qx/io/remote/transport/XmlHttp.js :: anonymous :: line 279" data: no]
我还查看了 Twitter 客户端教程,但是我设置的“dataChange”事件代替“tweetsChanged”事件从未被触发。任何帮助表示赞赏,谢谢。
最佳答案
这听起来像是跨域请求问题。 qx.io.remote.Request
使用 XHR 传输数据,由于浏览器的限制,这可能并非在所有情况下都有效。切换 crossDomain
对 true
的请求的标志将从 XHR 变为动态插入 script
标签没有跨域限制(但有其他限制)。
req.setCrossDomain(true);
也许这可以解决您的问题。
此外,您可以查看远程包的文档以获取有关跨域请求的更多详细信息:
http://demo.qooxdoo.org/current/apiviewer/#qx.io.remote
还要注意不要两次使用请求对象。唯一的工作一次。
关于web-services - 使用 Qooxdoo 从 Web 服务获取数据时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2384699/