Cross-domain requests with JQuery using YQL

后端 未结 4 1927
甜味超标
甜味超标 2021-01-16 17:29

So I need to make a a cross domain request where the response is not JSON formatted, so I cannot use .getJSON. .get obviously doesn\'t work because it is a cross domain requ

相关标签:
4条回答
  • 2021-01-16 17:43

    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!

    0 讨论(0)
  • 2021-01-16 17:51

    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.

    0 讨论(0)
  • 2021-01-16 17:55

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

    0 讨论(0)
  • 2021-01-16 18:03

    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...   
    });
    
    0 讨论(0)
提交回复
热议问题