Jquery getJSON Not Working Cross Site

后端 未结 1 1356
长情又很酷
长情又很酷 2021-01-24 14:32

I have a piece of javascript that grabs JSON data. When executed locally everything seems to work fine. However, when I try accessing it from a different site, it doesn\'t work.

相关标签:
1条回答
  • 2021-01-24 15:00

    From the documentation:

    • Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.

    • Script and JSONP requests are not subject to the same origin policy restrictions.

    You're going to need to use JSONP to get past the same-origin policy. jQuery can make this seamless (see the rest of the aforementioned documentation page).

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