Baidu Musicbox 用到的ajax代码
发布时间:2007-09-07 作者: 来源:转载
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")
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="
";
for(vari=0;iif(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+='- '+d+'.'+getTagValue(items[i],'songname').replace(//g,"")+linker[i]+'
';
}
tmp+="
";
$("toplist").innerHTML=tmp;
}
functions2(){
AJAXCALL("inc/songlist.asp?ac=all","s3","isXML=true");
}
functions3(doc){
varitems=getElementsByClass(doc,"item");
varlinker=newArray();
varlinkers=newArray();
vartmp="
";
for(vari=0;iif(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+='- '+d+'.'+getTagValue(items[i],'songname').replace(//g,"")+linker[i]+'
';
}
tmp+="
";
$("topalllist").innerHTML=tmp;
}
functionmusiclist(doc){
varitems=getElementsByClass(doc,"item");
vartmp="
";
for(vari=0;i<22&&ivard=i+1;
type=getTagValue(items[i],'type');
tmp+='- '+names.replace(//g,'')+'('+type+')
';
}
tmp+="
";
$("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="
";
for(vari=0;itmp+=''+getTagValue(items[i],'lrc')+'';
tl+=getTagValue(items[i],'time')+"|";
}
tmp+="
";
$("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="歌曲出处:"+link3.replace(//g,"")+"";
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='';
returnplayer;
}
functionrealplayer(str){
player='';
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;ivarpa=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;itmp+="删除