开发者

jQuery $.get() issue

I'm new with jQuery and JavaScript. I'm trying to make a HTTP GET request with the get() function. Below I've reported a part of my code. I don't understand why the http request doesn't work. Thanks for any advice!

    var jqxhr = $.get("http://lyricwiki.org/api.php?func=getSong&artist=Tool&song=Schism&fmt=xml", 
    function() {
         alert("success");
     })
    .success(function() { alert("second success"); })
    .error(functi开发者_JAVA百科on() { alert("error"); })
    .complete(function() { alert("complete"); });


I'm assuming you're serving this on a different domain than lyricwiki.org, in which case you're violating the same origin policy.


Edit: the good news is that they seem to have a funky alternative to JSONP that will let you request it cross-domain as a raw JavaScript file: http://lyrics.wikia.com/LyricWiki:REST#Response_Formats. Here's an example: http://lyrics.wikia.com/api.php?artist=Slipknot&song=Before_I_Forget&fmt=js


Your code is perfectly good, what i assume that your domains are different.

Domain where you execute code needs to be same as lyricwiki.org

That is cross domain policy and its not possible to get any data using AJAX from another domain.

IF this is the case try using JSONP

I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜