gpt4 book ai didi

java - XMLHttpRequest跨域资源共享(qooxdoo和tomcat)

转载 作者:行者123 更新时间:2023-11-30 11:56:15 24 4
gpt4 key购买 nike

我在 tomcat (http://localhost:8080/myrestfulapp/aservice/) 上部署了一个 Java REST 网络服务。

在我的 qooxdoo 应用程序中,我尝试使用 qx.io.remote.Request 发送 POST 请求。我构建了应用程序并将其部署在 apache HTTP 服务器(名为 http://myserver.org )上。当我尝试发送请求时,我在网络浏览器(Linux 上的 Chrome)的 javascript 控制台中收到此错误:Access-Control-Allow-Origin 不允许来源 http//myserver.org

我在 tomcat 的 ROOT webapp、/var/www 和我的 http 服务器的根目录中添加了 crossdomain.xml。我启用了 apache header (a2enmod header )并在服务器的配置文件中添加了 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 服务器名 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 应用发送跨源 http 请求到部署在 tomcat 上的 java 后端呢?

最佳答案

当您尝试使用 qooxdoo 访问其他域时,您必须将“qx.io.remote.Request”实例中的属性“crossDomain”设置为“true”:

req.setCrossDomain(true);

有关更多详细信息,请查看 API 文档: http://demo.qooxdoo.org/current/apiviewer/#qx.io.remote

关于java - XMLHttpRequest跨域资源共享(qooxdoo和tomcat),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4590367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com