Cross-domain requests with JQuery using YQL

自闭症网瘾萝莉.ら 提交于 2019-12-01 14:58:23

Well the page you linked you talks about using YQL and jQuery. It's a very interesting solution. However, your example seems to skip over the YQL part (which is crucial).

var urlToUse = "http://post.audioscrobbler.com/?hs=true&p=1.2.1&c=tst&v=1.0&u=chamals&t=" + ts + "&a=" + token + "&api_key=" + apiKey + "&sk=" + sk + "&format=xml&callback=cbfunc";

var yqlUrl2Use = "http://query.yahooapis.com/v1/public/yql?"+
            "q=select%20*%20from%20html%20where%20url%3D%22"+
            encodeURIComponent(urlToUse)+
            "%22&format=xml'&callback=?"
    // this function gets the data from the successful 
    // JSON-P call

Then you'll have to call the call the new URL as a JSONP req...

$.getJSON(yqlUrl2Use, function(json){
    // figure out the format of the answer here...   
});

Yeah, cross browser scripting. You can't AJAX anything like that since it violates the same domain policy.

You are going to have to setup a proxy on the same server the JavaScript is running from.

Edit Lookslike you need the $('#container').load(url) bit for that to work.

Go back an reread the linked article carefully.

You need to use $.getJSON rather than $.ajax() to return cross site information.

The var res actually has my information that I needed. I guess their headline = part was specifically for their implementation.

Thanks to those who helped!

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