How js+AJAX asynchronously collects all videos and information from Youku albums
This article mainly introduces how js+AJAX asynchronously collects all videos and information from Youku albums, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
Code
JavaScipt AJAX & regular expression test
Function wrt (s) {
Subret.value = s + "\ n" + subret.value
/ / subret.value + = "\ n" + s
}
Var objRequest; / / define a XML request object
Var previd = "", nowid = 0pr listid = "", iscancel=false; / / other variables
Function getlid () {
Var listid = weburl.value.match (/ playlist_show\ /. * (? = id_ (\ d +)). *\ .html $/ I)
If (! listid) {
Return null
} else {
Return listid [1]
}
}
Function retweb () {
If (objRequest.readyState = = 4 & & objRequest.status = = 200) {
/ / get callback
Var webstr = objRequest.responseText
Vid = webstr.match (/ var\ s+videoId\ swords =\ s * "(\ d +)"\ s match /) [1]
Vtitle = webstr.match (/ (. +)-(. +)-Video-Youku Video-online viewing (-)? /) [2]
Wrt (nowid + ":" + vtitle + "=" + vid)
If (previd = = vid) return
Previd = vid
Nowid + = 1
/ / start a new cycle
If (iscancel) return
Tstart ()
} else {
/ / alert ("callback failed!")
Return;// "error:" + objRequest.statusText
}
}
Function getweb (u) {
ObjRequest = new XMLHttpRequest (); / / new ActiveXObject ("Msxml2.XMLHTTP"); / / IE5&6 initializes the XMLHTTP object
ObjRequest.onreadystatechange = retweb; / / Asynchronous callback method
ObjRequest.open ("GET", uJing true)
ObjRequest.send (null)
}
Function tstart () {
If (listid== "") {
Listid=getlid ()
}
Url = "http://v.youku.com/v_playlist/f" + listid +" o1p "+ nowid +" .html "
Getweb (url)
}
# star