How to get ajax response from other domain?

2019-04-02 20:20发布

Except YQL ,Is there any way to get ajax's response and data from other domain without modifying server side's code?

YQL has limit (1000 calls per hour) for free user , but most of people said it's actually less.

3条回答
冷血范
2楼-- · 2019-04-02 20:42

You can use a HTML 5 feature which is postMessage to do cross domain calls. Again it is not supported in all the browsers. Look at the following link for implementation: Cross domain call using postMessage

查看更多
手持菜刀,她持情操
3楼-- · 2019-04-02 20:52

You can use the iframe receiver pattern. It's an old technique. See Secure Cross-Domain Communication in the Browser by Danny Thorpe on MSDN. You dont have to use JSONP but still can make cross-domain calls

查看更多
Evening l夕情丶
4楼-- · 2019-04-02 20:53

If what you mean by "without modifying server side's code" is not modifying the server of the data source, then you can have your own proxy server (basically making your own YQL server) to read the remote data. This is possible because the server-side is not bound to the Same-Origin Policy.

So you can AJAX your server, then let your server read the remote server using some form of wget, curl or fopen, and return what was retrieved:

Remote server <- fopen, curl or wget -> your server <- AJAX -> browser
查看更多
登录 后发表回答