i am having a problem with the below code , it whenever i would try to request a the JSON data from the website , i would always get back a response code 0. Does anyone know why
The status
code will be 0
for illegal cross-origin requests, see XMLHttpRequest status 0 (responseText is empty) and XMLHTTPRequest.status returns 0 and responseText is blank in FireFox 3.5.
Also, on FF the status code will be 0
for local file:// requests.
Looks like you are trying to request data from a host that is of different origin than yours. To elaborate this, if you have a site called www.example.com running in host A and you try to make a request to wwww.somethingelse.com running in host B, you would not be able to get the data from host B because most modern browsers enforce the same origin policy that prohibits the use of AJAX request in cross-site manner. If the browser detects this kind of "illegal request", it blocks the incoming data from that different host.
However, if you own that other host, you can explicitly pass a header to the browser which basically tells the browser to allow cross-site data from that other host. Read more about this here.