What is the ajax code used by Baidu Musicbox?
This article is to share with you about the ajax code used by Baidu Musicbox. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Var names
Var Cs, St
Var rorw= ""
Var lrcT
Function getname (songname) {
If (songname== "") {
Names=$ ("name"). Value
} else {
Names=songname
}
Geturl ()
}
Function geturl () {
AJAXCALL ("inc/songurl.asp?type=url1&keyword=" + names, "musiclist", "isXML=true")
Addbox (names)
}
Function top () {
AJAXCALL ("inc/songlist.asp?ac=new", "toplist", "isXML=true")
}
Function toplist (doc) {
Var items=getElementsByClass (doc, "item")
Var linker=new Array ()
Var linkers=new Array ()
Var tmp= ""
For (var ipos0witi0) disp_song_url=song_url.substring (0meme pos1pos2pos 4)
Var len2=MAX_DISP_LEN-3-getStrActualLen (disp_song_url)
If (len2 > 0) disp_song_url=disp_song_url+'...'+song_url.substring (len-len2,len)
Return disp_song_url
}
}
Function getStrActualLen (sChars) {
Return sChars.replace (/ [^\ X00 -\ xff] / g, "xx") .length
}
Function AJAXCALL (url,handleResponse,param) {
Var isXML=false;//false:html or true:xml
Var isCache=false;//false:no-cache or true:cache
Var method= "GET"; / / GET or POST
Var attach= ""
If (param) {
Re = / / g
Param=param.replace (re, "")
Var tmp=param.split (,)
For (var ionome0nteri0) {
Url+= "& t =" + t
} else {
Url+= "? t =" + t
}
}
Var postdata=null
If (method== "POST") {
Purl=url.split (?
Url=purl [0]
Postdata=purl [1]
}
RequestHTTP (url,handleResponse,method,isXML,postdata,attach)
}
Function RequestHTTP (burl,rdRandleResponse,bmethod,bXML,Formdata,attach) {
Var http_request = false
Function doHttpRequest () {
If (window.XMLHttpRequest) {
Http_request = new XMLHttpRequest ()
If (http_request.overrideMimeType) {
Http_request.overrideMimeType ('text/xml')
}
} else if (window.ActiveXObject) {
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP")
} catch (e) {
Try {
Http_request = new ActiveXObject ("Microsoft.XMLHTTP")
} catch (e) {}
}
}
If (! http_request) {
Alert ('Giving up: (Cannot create an XMLHTTP instance')
Return false
}
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)
}
}
Function handleStateChange () {
If (http_request.readyState==4 & & http_request.status==200) {
Var response_content
If (bXML) {
Response_content=http_request.responseXML
} else {
Response_content=http_request.responseText
}
If (typeof rdRandleResponse = = "function") {
RdRandleResponse (response_content, attach)
} else {
Eval (rdRandleResponse+ "(response_content,attach)")
}
}
}
DoHttpRequest ()
}
Function getTagValue (doc, tag) {
Var elems = doc.getElementsByTagName (tag) [0] .firstChild.nodeValue
Return elems
}
Function $(obj) {
Return document.getElementById (obj)
}
Function getElementsByClass (node,tag) {
Var els = node.getElementsByTagName (tag)
Return els
}
Lyrics function:
The copy code is as follows:
Function setcookie (name,value) {
Var Days = 30
Var exp = new Date ()
Exp.setTime (exp.getTime () + Days*24*60*60*1000)
[xss_clean] = name + "=" + escape (value) + "; expires=" + exp.toGMTString ()
}
Function getcookie (name) {
Var arr = [xss_clean] .match (new RegExp ("(^ |)" + name+ "= ([^;] *) (; | $")
If (arr! = null) return unescape (arr [2]); return null
}
Setcookie ("box", getcookie ("box"))
Function addbox (name) {
Var A1 roomname + "| * |"
Var box=getcookie ("box")
Box=box.replace (A1, "")
Var value=a1+box
Setcookie ("box", value)
Listbox ()
}
Function delbox (name) {
Var del=name+ "| * |"
Var s=getcookie ("box")
S = s.replace (del, "")
Setcookie ("box", s)
Listbox ()
}
Function listbox () {
Var tmp= ""
Var s2=getcookie ("box")
Var s3=s2.split ("| * |")
Var s4=s3.length-1
If (S4 > 8) $("boxlist") .style.height = "139px"
For (var iTuno Bandi)