response code 0 getting JSON from a website

前端 未结 2 1537
逝去的感伤
逝去的感伤 2021-01-27 06:49

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

相关标签:
2条回答
  • 2021-01-27 07:38

    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.

    0 讨论(0)
  • 2021-01-27 07:39

    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.

    0 讨论(0)
提交回复
热议问题