2010-10-07 56 views
0

我正在开发一个应用程序,它使用Netty编写的HTTP服务器发出跨源AJAX请求。XMLHttpRequest在Firefox 3.6.10中返回状态0,并且源自跨源请求

正在执行的Javascript代码类型的示例如下。

 $.ajax({ 
      type:"GET", 
      url:"http://localhost:5000/someresource", 
      data: { id1: "1", id2: "2" }, 
      success: function(status, textStatus, xhr) { 
       alert("Success") 
      }, 
      error: function(status, textStatus, xhr) { 
       alert("Error") 
      } 
     }); 

我看到的问题是,在Firefox(3.6.10和4.0测试版)的XMLHttpRequest的状态始终是0,不管响应的状态。在firebug中,我可以看到服务器正在返回请求的正确状态,但是这并没有被传递给XMLHttpRequest对象。

下面是发送

Response Headers 
Content-Type text/plain; charset=utf-8 
Content-Length 0 
Access-Control-Allow-Orig... http://localhost:9000 
Cache-Control no-cache 
Connection Keep-Alive 
Date Thu, 07 Oct 2010 07:52:08 GMT 

Request Headers 
Host localhost:5000 
User-Agent Mozilla/5.0.... 
Accept */* 
Accept-Language en-gb,en;q=0.5 
Accept-Encoding gzip,deflate 
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive 115 
Connection keep-alive 
Content-Type application/x-www-form-urlencoded 
Referer http://localhost:9000/test 
Origin http://localhost:9000 

我试图执行在Chrome,Opera和Safari,他们都做工精细的代码的请求和响应头。这是我正在做的事情还是Firefox中的错误?

在此先感谢。

+0

这是一个尚未解决的问题吗?我好像在Chrome 16和Firefox 10.0上获得了有关302重定向,XHR和CORS的错误行为。非重定向工作正常。 – ricosrealm 2012-03-02 19:05:00

回答

1

我在firefox 3.6+和chrome中看到过这个问题。我发现的原因是我在本地主机服务器上调试站点。这两种方法只会在从远程URL运行时才会返回适当的响应代码。他们都返回本地主机的不同状态码。