deepak
deepak

Reputation: 9

XMLHttpRequest request is resultin in ReadyState 4 and status is 200

I am trying to make a XMLHttpRequest Request to a content which is on local, runnin on local webserver from a HTML File and javascript residing locally.

it will hit the webserver request, and then even thou it sends the data back, in my javascript, at once I get readyState 4 and status as 0.

If i try putting the pages in the webserver foloder and access them as webpage slke http;//localhost/ filename then it works fine.

Upvotes: 0

Views: 3416

Answers (1)

Andy E
Andy E

Reputation: 344585

This is to do with the fact that HTTP status codes are returned by web servers and, since you're accessing the local file system, a status code can't be returned -- hence Unknown (0). Some links:


Following your comments, it's a little clearer as to what is causing your problem. XMLHttpRequests are restricted in each browser by the Same origin policy. If you try to access a file on a different domain, port or protocol the request will return a status code of 0 and nothing for responseText. The most suitable workaround for the time being is JSON with Padding.

Upvotes: 3

Related Questions