Where did you install Firefox from? Help Mozilla uncover 3rd party websites that offer problematic Firefox installation by taking part in our campaign. There will be swag, and you'll be featured in our blog if you manage to report at least 10 valid reports!

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

XMLHttpRequest returns status of 0 for cross origin resource requests

  • 3 回覆
  • 33 有這個問題
  • 34 次檢視
  • 最近回覆由 shob07

more options

Hi,

I am developing an application that makes a cross origin AJAX request to an HTTP server written using Netty.

An example of the type of Javascript code being executed is below.

           $.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")
               }
           });

The problem I am seeing is that on Firefox (3.6.10 and 4.0 beta) the status of the XMLHttpRequest is always 0, regardless of the status of the response. In firebug I can see that the server is returning the correct status for the request, but this is not being pushed through to the XMLHttpRequest object.

Below is the request and response headers being sent

>     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

I have tried executing the code in Chrome, Opera and Safari and they all work fine. Is this something I am doing or a bug in Firefox?

Thanks in advance.

Hi, I am developing an application that makes a cross origin AJAX request to an HTTP server written using Netty. An example of the type of Javascript code being executed is below. $.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") } }); The problem I am seeing is that on Firefox (3.6.10 and 4.0 beta) the status of the XMLHttpRequest is always 0, regardless of the status of the response. In firebug I can see that the server is returning the correct status for the request, but this is not being pushed through to the XMLHttpRequest object. Below is the request and response headers being sent <pre><nowiki>> 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 </nowiki></pre> I have tried executing the code in Chrome, Opera and Safari and they all work fine. Is this something I am doing or a bug in Firefox? Thanks in advance.

由 cor-el 於 修改

所有回覆 (3)

more options

A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.

The helpers at that forum are more knowledgeable about web development issues.

You need to register at the mozillaZine forum site in order to post at that forum.

See http://forums.mozillazine.org/viewforum.php?f=25

more options

Ok thanks, I will do so

more options

I am also facing the same issue. Someone please let me know how to resolve the same.

Thanks

由 shob07 於 修改