I am trying to execute XMLHttpRequest from a local file (file: //) using JQuery.ajax for something on http: // and from what I see it looks like the request is coming out (success callback is being called and Firebug shows the request) but thereβs simply no answer.
Here is basically what I am doing:
$.ajax({ url: "https://stackoverflow.com/users/63736/bruce-van-der-kooij", dataType: "text", success: function(text) { alert(text) } })
Note. I use datatype: "text" , but it really doesn't matter what you use.
This will show an empty warning.
Now, if I were to guess, I should say that this is related to the same origin policy, but I am not getting the typical NS_ERROR_DOM_SECURITY_ERR exception (there are no errors in the console at all).
Does anyone have an explanation of what is happening?
Similar
UPDATE:
So, I came across a July 2009 article on hacks.mozilla.org , which seems to explain what is happening. Firefox> = 3.5 appears to be implementing the Cross-Origin Resource Sharing Specification (CORS) , which provides a mechanism for you to perform cross-site requests. What happens in this case is explained in the article:
In Firefox 3.5 and Safari 4, the XMLHttpRequest gateway will not successfully retrieve the resource unless the server provides the appropriate CORS headers (in particular, the Access-Control-Allow-Origin header) back with the resource, although the request will go through.
Please note that in my case, the request is sent with the Origin: null heading and a 200 OK response is returned. However, the server does not send the corresponding headers back, so the response body is not retrieved.
See also: