How to get ajax response from other domain?

我与影子孤独终老i 提交于 2019-12-05 06:40:26

问题


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.


回答1:


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



回答2:


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:


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



来源:https://stackoverflow.com/questions/11278545/how-to-get-ajax-response-from-other-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!