Baidu Musicbox 用到的ajax代码

人生不过三万天,成功失败均坦然,是非恩怨莫在意,健康快乐最值钱。你的爱好就是你的方向,你的兴趣就是你的资本。
varnames;
varCs,St;
varrorw="";
varlrcT; functiongetname(songname){
if(songname==""){
names=$("name").value;
}else{
names=songname;
}
geturl();
}
functiongeturl(){
AJAXCALL("inc/songurl.asp?type=url1&keyword="+names,"musiclist","isXML=true");
addbox(names);
}
functiontop(){
AJAXCALL("inc/songlist.asp?ac=new","toplist","isXML=true");
}
functiontoplist(doc){
varitems=getElementsByClass(doc,"item");
varlinker=newArray();
varlinkers=newArray();
vartmp="<ul>";
for(vari=0;i<items.length;i++){
if(getTagValue(items[i],"singer")=="")
{
linker[i]="";
linkers[i]="";
}
else
{
linker[i]="("+getTagValue(items[i],'singer').replace(//g,"")+")";
linkers[i]=""+getTagValue(items[i],'singer').replace(//g,"");
}
vard=i+1;
tmp+='<li>'+d+'.<arel="nofollow noopener noreferrer" href=javascript:getname("'+getTagValue(items[i],'songname').replace(//g,"")+linkers[i]+'")title="'+getTagValue(items[i],"songname').replace(//g,"")+linker[i]+'">'+getTagValue(items[i],'songname').replace(//g,"")+linker[i]+'</a></li>';
}
tmp+="</ul>";
$("toplist").innerHTML=tmp;
}
functions2(){
AJAXCALL("inc/songlist.asp?ac=all","s3","isXML=true");
}
functions3(doc){
varitems=getElementsByClass(doc,"item");
varlinker=newArray();
varlinkers=newArray();
vartmp="<ul>";
for(vari=0;i<items.length;i++){
if(getTagValue(items[i],"singer")=="")
{
linker[i]="";
linkers[i]="";
}
else
{
linker[i]="("+getTagValue(items[i],'singer').replace(//g,"")+")";
linkers[i]=""+getTagValue(items[i],'singer').replace(//g,"");
}
vard=i+1;
tmp+='<li>'+d+'.<arel="nofollow noopener noreferrer" href=javascript:getname("'+getTagValue(items[i],'songname').replace(//g,"")+linkers[i]+'")title="'+getTagValue(items[i],"songname').replace(//g,"")+linker[i]+'">'+getTagValue(items[i],'songname').replace(//g,"")+linker[i]+'</a></li>';
}
tmp+="</ul>";
$("topalllist").innerHTML=tmp;
}
functionmusiclist(doc){
varitems=getElementsByClass(doc,"item");
vartmp="<ul>";
for(vari=0;i<22&&i<items.length;i++){
vard=i+1;
type=getTagValue(items[i],'type');
tmp+='<li><imgsrc="img/list.gif"/><atitle="试听点"+d+'('+type+')"rel="nofollow noopener noreferrer" href=javascript:play("'+getTagValue(items[i],'type')+'","'+getTagValue(items[i],'link').replace(//g,'')+'")>'+names.replace(//g,'')+'('+type+')</a></li>';
}
tmp+="</ul>";
$("list").innerHTML=tmp;
$("msg").style.display="none";
play(getTagValue(items[0],"type"),getTagValue(items[0],"link"));
}
functionplay(obj,url){
initLrc();
$("guanxin").style.display="none";
$("msg").style.display="block";
AJAXCALL("inc/songurl.asp?type=url2&keyword="+url+"&attach="+obj,"gotoplay","isXML=true");
AJAXCALL("inc/lyrics.asp?song="+names,"getlrc","isXML=true");
}
vartl;
functiongetlrc(doc){
tl="";
varitems=getElementsByClass(doc,"item");
vartmp="<divid=LrcDivclass=LrcDiv>";
for(vari=0;i<items.length;i++){
tmp+='<divclass=divid=T_'+getTagValue(items[i],'time')+'onclick=To(\''+getTagValue(items[i],'time')+'')>'+getTagValue(items[i],'lrc')+'</div>';
tl+=getTagValue(items[i],'time')+"|";
}
tmp+="</div>";
$("lrc").innerHTML=tmp;
} functiongotoplay(docs){
vartype=getTagValue(docs,"type");
varlink=getTagValue(docs,"link");
if(type=="rm"||type=="ra"||type=="ram"||type=="rmvb"||type=="mpga"||type=="mp4"||type=="3gp")
$("players").innerHTML=realplayer(link);
else
$("players").innerHTML=mdplayer(link);
varlink3=cuturl(link);
$("msg").style.display="none";
$("wmaurl").innerHTML="歌曲出处:<arel="nofollow noopener noreferrer" href="+link.replace(//g,"")+"target='_blank'title="点右键另存:"+names.replace(//g,"")+"'>"+link3.replace(//g,"")+"</a>";
setTimeout(guanxin,1000);
playobj();
} functioninitLrc(){
clearTimeout(lrcT);
rorw="";
$("players").innerHTML="";
$("lrc").innerHTML="";
St=0;
Cs=0;
} functionplayobj(){
if($("MPlayer"))
{
rorw="wmp";
ldL();
}
elseif($("RPlayer"))
{
rorw="rmp";
try{RPlayer.SetWantErrors(true);}catch(hh){}
ldL();
}
else
playobj();
} functionguanxin(){
$("guanxin").style.display="block";
setTimeout(guanxin2,10000);
}
functionguanxin2(){
$("guanxin").style.display="none";
} varplayer;
functionmdplayer(str){
player='<objectclassid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6"id="MPlayer"width="100%"height="64"><paramname="url"value="'+str+'"><paramname="enablecontextmenu"value="0"><paramname="enableerrordialogs"value="0"></object>';
returnplayer;
} functionrealplayer(str){
player='<objectclassid="clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa"id="RPlayer"width="100%"height="60"><paramname="src"value="'+str+'"><paramname="controls"value="controlpanel,statusbar"><paramname="autostart"value="true"></object>';
returnplayer;
} functioncuturl(song_url){
varlen=getStrActualLen(song_url);
varMAX_DISP_LEN=40;
if(len<=MAX_DISP_LEN)returnsong_url;
vardisp_song_url=song_url;
varpos1=song_url.indexOf("://");
if(pos1>0){
disp_song_url=song_url.substring(pos1+3,len);
varpos2=disp_song_url.indexOf("/");
if(pos2>0)disp_song_url=song_url.substring(0,pos1+pos2+4);
varlen2=MAX_DISP_LEN-3-getStrActualLen(disp_song_url);
if(len2>0)disp_song_url=disp_song_url+'...'+song_url.substring(len-len2,len);
returndisp_song_url;
}
} functiongetStrActualLen(sChars){
returnsChars.replace(/[^\x00-\xff]/g,"xx").length;
} functionAJAXCALL(url,handleResponse,param){
varisXML=false;//false:htmlortrue:xml
varisCache=false;//false:no-cacheortrue:cache
varmethod="GET";//GETorPOST
varattach="";
if(param){
re=//g;
param=param.replace(re,"");
vartmp=param.split(",");
for(vari=0;i<tmp.length;i++){
varpa=tmp[i].substr(0,3);
varct=tmp[i].split("=")[1];
switch(pa){
case"isX":
if(ct=="true"){
isXML=true;
}else{
isXML=false;
}
break;
case"isC":
if(ct=="true"){
isCache=true;
}else{
isCache=false;
}
break;
case"met":
method=ct;
break;
case"att":
attach=ct;
break;
}
}
}
if(!isCache){
vart=newDate().getTime();
if(url.indexOf("?")>0){
url+="&t="+t;
}else{
url+="?t="+t;
}
}
varpostdata=null;
if(method=="POST"){
purl=url.split("?");
url=purl[0];
postdata=purl[1];
}
RequestHTTP(url,handleResponse,method,isXML,postdata,attach);
} functionRequestHTTP(burl,rdRandleResponse,bmethod,bXML,Formdata,attach){
varhttp_request=false;
functiondoHttpRequest(){
if(window.XMLHttpRequest){
http_request=newXMLHttpRequest();
if(http_request.overrideMimeType){
http_request.overrideMimeType('text/xml');
}
}elseif(window.ActiveXObject){
try{
http_request=newActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
http_request=newActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!http_request){
alert('Givingup:(CannotcreateanXMLHTTPinstance');
returnfalse;
}
http_request.onreadystatechange=handleStateChange;
http_request.open(bmethod,burl,true);
if(Formdata){
http_request.setRequestHeader("Content-Length",Formdata.length);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http_request.send(Formdata);
}else{
http_request.setRequestHeader("Content-Type","text/html");
http_request.send(null);
}
}
functionhandleStateChange(){
if(http_request.readyState==4&&http_request.status==200){
varresponse_content;
if(bXML){
response_content=http_request.responseXML;
}else{
response_content=http_request.responseText;
}
if(typeofrdRandleResponse=="function"){
rdRandleResponse(response_content,attach);
}else{
eval(rdRandleResponse+"(response_content,attach)");
}
}
}
doHttpRequest();
} functiongetTagValue(doc,tag){
varelems=doc.getElementsByTagName(tag)[0].firstChild.nodeValue;
returnelems;
} function$(obj){
returndocument.getElementById(obj);
} functiongetElementsByClass(node,tag){
varels=node.getElementsByTagName(tag);
returnels;
}
歌词函数:

functionsetcookie(name,value){
varDays=30;
varexp=newDate();
exp.setTime(exp.getTime()+Days*24*60*60*1000);
document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
}
functiongetcookie(name){
vararr=document.cookie.match(newRegExp("(^|)"+name+"=([^;]*)(;|$)"));
if(arr!=null)returnunescape(arr[2]);returnnull;
}
setcookie("box",getcookie("box"));
functionaddbox(name){
vara1=name+"|*|";
varbox=getcookie("box");
box=box.replace(a1,"");
varvalue=a1+box;
setcookie("box",value);
listbox();
}
functiondelbox(name){
vardel=name+"|*|";
vars=getcookie("box");
s=s.replace(del,"");
setcookie("box",s);
listbox();
}
functionlistbox(){
vartmp="";
vars2=getcookie("box");
vars3=s2.split("|*|");
vars4=s3.length-1;
if(s4>8)$("boxlist").style.height="139px";
for(vari=0;i<s4;i++){
tmp+="<divid=\"box\"><divid=\"del\"style=\"float:right;\"><spanonclick=javascript:delbox('"+s3[i]+"')>删除</span></div><divid=\"boxtitle\"><arel="nofollow noopener noreferrer" href=javascript:getname('"+s3[i]+"')>"+s3[i]+"</a></div></div>";
}
$("boxlist").innerHTML=tmp;
} functionGetEBID(id){returndocument.getElementById(id);}
functionTo(t){
if(rorw=="")return;
if(rorw=="rmp"&&RPlayer.GetPlayState()==3)RPlayer.SetPosition(t*1000);
if(rorw=="wmp"&&MPlayer.playState==3)MPlayer.controls.CurrentPosition=t;
} functionlrcrun(){
varrtl="|"+tl;
if((rtl.indexOf("|"+Cs+"|"))!=-1){
GetEBID("LrcDiv").scrollTop=GetEBID("LrcDiv").offsetTop-parseInt(GetEBID("LrcDiv").offsetHeight/2)+GetEBID("T_"+Cs).offsetTop+10;
GetEBID("T_"+St).className="";
GetEBID("T_"+Cs).className="b";
St=Cs;
}
} functionldL(){
if(rorw=="rmp"&&RPlayer.GetPlayState()==3){Cs=Math.floor(RPlayer.GetPosition()/1000);lrcrun();}
if(rorw=="wmp"&&MPlayer.playState==3){Cs=Math.floor(MPlayer.controls.CurrentPosition);lrcrun();}
lrcT=setTimeout("ldL()",10);
}

到此这篇关于Baidu Musicbox 用到的ajax代码就介绍到这了。当一个人先从自己的内心开始奋斗,他就是个有价值的人。更多相关Baidu Musicbox 用到的ajax代码内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
详解在Angular4中使用ng2-baidu-map的方法