Why Is Xmlhttprequest.status == 0 On All The Browsers Except Ie?
Solution 1:
Internet Explorer uses a different object than the other browsers to make Ajax requests. Microsoft used the Microsoft.XMLHTTP object, while the other browsers use the XMLHttpRequest object.
There's an article here explaining it and explaining how to do a workaround.
http://ajaxpatterns.org/Cross-Browser_Component
Your best bet is to use one of the many libraries out there for making Ajax requests. the'll handle the abstraction for you. I see your post is tagged as C#. If this is the case and you're developing pages with Asp.NET, you could be using the standard Asp.Net Ajax tools (a ScriptManager and an UpdatePanel) although an awful lot of people prefer to use JQuery.
Solution 2:
The present problem is related with the same origin policy. I've found 2 articles on StackOverflow that helped me to identify the problem:
- XMLHTTPRequest.status returns 0 and responseText is blank in FireFox 3.5
- Ways to circumvent the same-origin policy
The solution for the problem is here! I added the following line to the method of the server:
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
By adding this line for each method, the response's header comes as follow:
HTTP/1.1200OKContent-Length:81Content-Type:application/json;charset=utf-8Server:Microsoft-HTTPAPI/1.0Access-Control-Allow-Origin:*Date:Sun,31Oct2010 02:34:34 GMT<jsondata>
This way the service works on Firefox, Safari, Chrome and IE. But, as is said on the link with the answer, there must be a better way to solve this. I'll try to find something about that :)
Post a Comment for "Why Is Xmlhttprequest.status == 0 On All The Browsers Except Ie?"