jquery - 获取ajax响应并存储在变量中

时间:2014-04-23 12:32:45

标签: jquery ajax jsonp

我想将从http://www.youtube-mp3.org/a/itemInfo/?video_id=Vd85aPZ-QAE&ac=www&t=grp收到的数据存储到变量中并访问info.h ..我试过这个

$.ajax({
          async: false,
          type: "GET",
          url: "http://www.youtube-mp3.org/a/itemInfo/?video_id=Vd85aPZ-QAE&ac=www&t=grp",
          dataType: "json",
          success : function(info) {
                        xml = info.h;
                alert(xml); // WORKS
                    }
        });

但没有成功..

infoRehashCallback=function(){4==h.readyState&&("$$$ERROR$$$"==h.responseText?pushItemError():500==h.status?(error_count+=1,4<error_count&&pushItemMaintenance()):(eval(h.responseText),checkInfo()))};infoRehash=function(){var a=new Date;h=createRequestObject();a="http://www.youtube-mp3.org/a/itemInfo/?video_id="+video_id+"&ac=www&t=grp&r="+a.getTime();h.onreadystatechange=infoRehashCallback;h.open("GET",a,!0);hs(h);h.send(null)};
startInfoRehash=function(a){video_id=a;infoRehash();interval=window.setInterval("infoRehash()",1E3*interval_diff)};

我从网站的javascript

获取此代码

2 个答案:

答案 0 :(得分:0)

制作这样的函数:

$.ajax({
          async: false,
          type: "GET",
          url: "http://www.youtube-mp3.org/a/itemInfo/?video_id=Vd85aPZ-QAE&ac=www&t=grp",
          dataType: "json",
          success : function(info) {
                        ShowAlert(info.h);

                    }
        });

function ShowAlert(a)
{
   alert(a);
// do whatever want to with the result
}

答案 1 :(得分:0)

我收到了以下无效json的回复:

info = {"status" : "serving", "h" : "-"};

应该是:

{"status" : "serving", "h" : "-"}