开发者

XMLHttpRequest returns status of 0 in Firefox 3.6.10 and up from cross origin requests

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:"ht开发者_高级运维tp://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.


I have seen this problem in both firefox 3.6+ and chrome. The reason i found is that i was debugging the site on the localhost server. Both of these will only return the appropriate response codes when it is ran from a remote url. They both return different status codes for localhost.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜