2010-10-07 60 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運行時纔會返回適當的響應代碼。他們都返回本地主機的不同狀態碼。