简体   繁体   中英

How to use cross-domain json data?

I wish to access this json list: http://www.westwing.de/campaign/top/?limit=5&bp=1&json=1 and turn it into usable html on my page. There is one issue, the server my site runs on is a test server and does not have the same domain name (westwing.de).

I read that you could insert it as a script tag in your document's head and use JSONP but when I do that and open the script in chrome it returns the website's homepage, not the json list.

I don't have any access to the server so can't change settings etc.

Could someone point me to a good example of this or explain it to me?

  1. You cannot do x-domain JSON, unless the server supports CORS (which this one doesn't).

  2. You can do x-domain JSONP, but that requires the coooperation of the server (which you don't have), as the server needs to return a JSONP response, rather than plain JSON. See Can anyone explain what JSONP is, in layman terms? .

  3. If the test server is on *.westwing.de , you can set document.domain = "westwing.de" on your client, which will allow you to make JSON requests as normal (as the pages will then be on the same domain).

  4. If the above doesn't apply, your best option is to write your own page on your test server, which acts as a proxy between your test domain and westwing.de (as your server side code won't be restricted by the SOP ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM