How do I use external JSON…?

后端 未结 3 853
伪装坚强ぢ
伪装坚强ぢ 2021-01-07 00:49

spent a few hours trying to figure this out, but cannot for the life of me figure out what\'s going wrong.

All I\'m trying to do is load this:

https:         


        
3条回答
  •  青春惊慌失措
    2021-01-07 00:58

    JSONP relies on the server to return a JSONP formatted response. Basically, to use JSONP the server needs to return a JSON string wrapped in a function invocation ({"foo":1} becomes func({"foo":1})).

    As the server your using doesn't return a JSONP response, you cannot use JSONP, you can only use JSON.

    This is a shame, as JSON cannot be used x-domain due to the same origin policy (SOP). Therefore, the only option you have is to use a proxy server, which retrieves the JSON from the server, and either gives it to you in JSONP (see Yahoo Pipes), or which is on the same domain as the requested page (write a simple PHP script to get the file using file_get_contents() and then echo the output), in which case it can return the JSON.

提交回复
热议问题