XMLHttpRequest跨域资源共享(qooxdoo和tomcat)
我在 tomcat 上部署了一个 Java REST Web 服务 (http://localhost:8080/myrestfulapp/aservice/)。
在我的 qooxdoo 应用程序中,我尝试使用 qx.io.remote.Request 发送 POST 请求。 我构建了该应用程序并将其部署在 apache HTTP 服务器(名为 http://myserver.org)上。 当我尝试发送请求时,我在网络浏览器(Linux 上的 Chrome)的 javascript 控制台中收到此错误: Access-Control-Allow-Origin 不允许 Origin http//myserver.org
我在 tomcat 的根 web 应用程序、/var/www 和我的 http 服务器的根目录中添加了 crossdomain.xml。 我启用了 apache 标头(a2enmod 标头),并在服务器的配置文件中添加了 Access-Control-Allow-Origin "*"。
这是我的 qooxdoo 函数发送请求:
envoyer : function(id, nom, prenom, poste)
{
var url = "http://localhost:8080/helloworld/enregistrer";
var donnees = "{ \"id\":" + id + ", \"nom\":\"" + nom + "\", \"prenom\":\"" + prenom + "\", \"poste\":\""+poste +"\" }";
alert(donnees);
var req = new qx.io.remote.Request(url, "POST", "application/json");
req.setData(donnees);
req.addListener("completed", function(e) {
alert(e.getContent());
});
req.send();
}
这是 myserver.org 配置文件: ServerAdmin webmaster@localhost serverName myserver.org
DocumentRoot /home/jihedamine/HttpServer
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/jihedamine/HttpServer/>
Header set Access-Control-Allow-Origin "*"
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
那么我如何能够从 qooxdoo 应用程序向部署在 tomcat 上的 java 后端发送跨源 http 请求?
I have a Java REST webservice deployed on tomcat (http://localhost:8080/myrestfulapp/aservice/).
In my qooxdoo app, I try to send a POST request using qx.io.remote.Request.
I built the application and deployed it on an apache HTTP server (named http://myserver.org).
When I try to send the request, I get this error in javascript console of my web browser (Chrome on linux):
Origin http//myserver.org is not allowed by Access-Control-Allow-Origin
I added crossdomain.xml in tomcat's ROOT webapp, in /var/www and in my http server's root directory.
I enabled apache headers (a2enmod headers) and I added Access-Control-Allow-Origin "*" in my server's configuration file.
here is my qooxdoo function sending the request:
envoyer : function(id, nom, prenom, poste)
{
var url = "http://localhost:8080/helloworld/enregistrer";
var donnees = "{ \"id\":" + id + ", \"nom\":\"" + nom + "\", \"prenom\":\"" + prenom + "\", \"poste\":\""+poste +"\" }";
alert(donnees);
var req = new qx.io.remote.Request(url, "POST", "application/json");
req.setData(donnees);
req.addListener("completed", function(e) {
alert(e.getContent());
});
req.send();
}
and here is the myserver.org configuration file:
ServerAdmin webmaster@localhost
serverName myserver.org
DocumentRoot /home/jihedamine/HttpServer
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/jihedamine/HttpServer/>
Header set Access-Control-Allow-Origin "*"
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
So how could I enable sending cross origin http requests from a qooxdoo app to a java backend deployed on tomcat ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您尝试使用 qooxdoo 访问其他域时,您必须将“qx.io.remote.Request”实例中的“crossDomain”属性设置为“true”:
有关更多详细信息,请查看 API 文档:
http://demo.qooxdoo.org/current/apiviewer/#qx.io .remote
When you try to access a other domain with qooxdoo you have to set the property "crossDomain" from your "qx.io.remote.Request" instance to "true":
For more details have a look at the API doc:
http://demo.qooxdoo.org/current/apiviewer/#qx.io.remote