How to request different domain with Ajax in jQuery

拈花ヽ惹草 提交于 2019-12-23 17:47:44

问题


I need to make a request to a different domain with Ajax in jQuery!

Should I use iframe?

Edited:

On facebook.com working chat, with few different domain name?

GET http:// www.facebook.com/ajax/presence/reconnect.php?__a=1&reason=6&iframe_loaded=false&post_form_id=23be2df75b74a0bcb61358814c56ba4f 200 OK

GET http://0.50.channel.facebook.com/x/2562941315/4271808869/true/p_1529934952=2 200 OK

I want something like...


回答1:


You can not because of same origin policy.

You have a few options.

JSONP

You make a request with a script element, and pass it a callback to one of your functions to handle the data.

Server side proxy

Basically, you create a wrapper on the server side. You can use cURL or equivalent. Request the data with your server and then serve it from under the same domain.




回答2:


You can't. Consider using JSONP instead, which uses <script> tags to retrieve data.




回答3:


Take a look at http://api.jquery.com/jQuery.getJSON/ and JSONP



来源:https://stackoverflow.com/questions/4011156/how-to-request-different-domain-with-ajax-in-jquery

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