2

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

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

我在 tomcat 的 ROOT webapp、/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>

那么如何才能将跨源 http 请求从 qooxdoo 应用程序发送到部署在 tomcat 上的 java 后端呢?

4

1 回答 1

1

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

req.setCrossDomain(true);

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

于 2011-01-10T12:12:00.170 回答