JSON: How do I make cross-domain JSON call

前端 未结 8 809
情歌与酒
情歌与酒 2020-11-30 06:54

I try to run the following jquery code in local Network.

 $.ajax({
     type: \"GET\",
     url: \"http://SomeSite/MyUrl/\",
     cache: false,
     data: {         


        
相关标签:
8条回答
  • 2020-11-30 07:36

    Do you have server access to 'SomeSite', or is it 3rd party?

    • If you have access you can enable CORS wp, home on it. In its simplest form (data is not session sensitive), just add the header: Access-Control-Allow-Origin: *

    • If you don't have access do you know whether it supports JSONP wp, so? This typically involves passing at least a callback parameter in the URL. (Of course if you have access you can add JSONP support too.)

    • If you don't have access to make changes to 'SomeSite' and it supports neither CORS nor JSONP, you might be able to use YQL wp, home as a proxy. It does support both CORS and JSONP and can even translate data formats, select some part of the data, etc.
      (Note that YQL respects robots.txt so if it's a 3rd party site that restricts automated access you might still be out of luck.)

    0 讨论(0)
  • 2020-11-30 07:48

    You can try jsonp request http://api.jquery.com/jQuery.ajax/ see crossdomain

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