How to make an ajax with JQuery with cross site scripting?

£可爱£侵袭症+ 提交于 2020-01-01 18:58:34

问题


i'm with a problem that i have to get the json from here:

http://templodasdeusas.com.br/game/srv/game.php?srv=home

there is an option too to add callback function name like:

http://templodasdeusas.com.br/game/srv/game.php?srv=home&callback=myFunction

that will return something like: myFunction({'msgd':'value'});

i want to make um ajax request using jQuery, is that possible? i still receiving error with the normal $.ajax request, i was told that i must use jsonp or cross site scripting... how it works? someone got an exemple? tnx!!


回答1:


jQuery does this transparently for you, if you put callback=? in the URL. See the API entry for $.getJSON. You can basically forget about the cross-domain nature of the request.

So you might do something like this:

$.getJSON(
    'http://templodasdeusas.com.br/game/srv/game.php?srv=home&callback=?',
     function(data) {
         // use the response, contained in the data object, e.g.
         alert(data.msgd);
     }
);



回答2:


See this:

http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html

and this:

http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/



来源:https://stackoverflow.com/questions/6284617/how-to-make-an-ajax-with-jquery-with-cross-site-scripting

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