用Ajax获取网通电影列表。

  • 周末没事,在重庆网通看连续剧,不过他没有提供一个很好的列表页面,一个列表页面没有提供翻页功能,只有700个电影列表,不能看到以前的连续剧。一个页面有翻页,但是每页只有10个影片,连续剧有200多个页面,要看以前的连续剧也要翻页很多次,在 [原创]Ajax基本原理讲解 里面的程序的基础上修改了一下,获取了所以连续剧的列表,方便观看。
    cqcnc.gif

    大致原理如下:
  • 用xmlhttp获取第一页源文件。
  • 从源文件中提取影片的标题和地址,在页面中显示
  • 获取下一页的源文件,提取标题和地址并显示。
  • 重复,直到最后一页

源代码写得很乱,仅供参考。下载: cqcnc.zip

ContractedBlock.gif ExpandedBlockStart.gif
None.gif<HTML>
None.gif
<HEAD>
None.gif
<TITLE> 网通电影地址 </TITLE>
None.gif
<META NAME="Author" CONTENT="http://pharaoh.cnblogs.com">
None.gif
</HEAD>
None.gif
<BODY>
None.gif
None.gif
<div id=load style="display:none; position:absolute;right:0px;top:0px;background:#FF5B5B;border:1px solid">正在加载dot.gif</div> 
None.gif
None.gif
None.gif
<input id=wurl style="width:500px" value="http://cncxp.cqwin.com/mov_list.asp?page={0}&class2id=9&Nclassid=&order=&updown=">
None.gif开始页:
<input id=pagestart value='1'style="width:50px" />结束页:<input id=pageend value="216" style="width:50px" />
None.gif
<button onclick="Begin();">加载</button>
None.gif
<button onclick="stop();">停止</button>
None.gif
<!--
None.gif<hr />
None.gif<div id=city>片断</div>
None.gif<hr />
None.gif<center><div id="wuhan_weather">数据区域</div></center>
None.gif<hr />
None.gif<div id=stext>代码区</div>
None.gif
-->
ExpandedBlockStart.gifContractedBlock.gif
<script language="javascript">dot.gif
InBlock.gif    
var loading = false;
InBlock.gif    
var bgTime;
InBlock.gif    
function Begin()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        bgTime 
= new Date();
InBlock.gif        InsertHtml('
<br />开始时间:'+bgTime);
InBlock.gif        loading 
= true;
InBlock.gif        GetWeather();
ExpandedSubBlockEnd.gif    }

InBlock.gif  
function stop()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif      loading 
= false;
ExpandedSubBlockEnd.gif  }

InBlock.gif 
var xmlhttp ;
InBlock.gif 
function InsertHtml(html)
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif     
InBlock.gif     document.body.insertAdjacentHTML('beforeEnd',html);
ExpandedSubBlockEnd.gif}

InBlock.gif 
function GetWeather()
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif         
if(!loading) return;
InBlock.gif     
if(parseInt(document.getElementById('pagestart').value,10> parseInt(document.getElementById('pageend').value,10)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif         
var endTime = new Date();
InBlock.gif         InsertHtml('
<br />结束时间:'+endTime+"<br />用时:"+(endTime - bgTime)/1000+"");
InBlock.gif         
return;
ExpandedSubBlockEnd.gif     }

InBlock.gif         window.status 
= '';
InBlock.gif         document.all(
"load").style.display='';
InBlock.gif         
if(!xmlhttp)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif     xmlhttp 
= new ActiveXObject("Msxml2.XMLHTTP");
InBlock.gif     xmlhttp.onreadystatechange 
= getReady;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif     xmlhttp.Open(
"GET",document.getElementById('wurl').value.replace('dot.gif{0}',document.getElementById('pagestart').value),true);
InBlock.gif     xmlhttp.Send();
ExpandedSubBlockEnd.gif}

InBlock.gif
function getReady()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    window.status 
+= xmlhttp.readyState+' ';
InBlock.gif   
if(xmlhttp.readyState == 4)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif       document.all(
"load").style.display='none';
InBlock.gif     
if(xmlhttp.status == 200)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif        
var xmlReturn = bytes2BSTR(xmlhttp.ResponseBody);  //xmlhttp.responseText;
InBlock.gif

InBlock.gif        
//document.all("wuhan_weather").innerHTML=xmlReturn;
InBlock.gif
        //document.all("stext").innerText=xmlReturn;
InBlock.gif
        
InBlock.gif    
InBlock.gif        
var newText = xmlReturn;//xmlReturn.replace(/\n+/g,' ');
InBlock.gif
        //document.all("stext").innerText=newText;
InBlock.gif
        var re = /<a class="date".+?a>/ig;
InBlock.gif        
var cityText = newText.match(re);
InBlock.gif        
var page = document.getElementById('pagestart').value;
InBlock.gif        
var alink = '<hr /><a href="'+document.getElementById('wurl').value.replace('{0}',page)+'" target="_blank">第'+page+'页';
InBlock.gif        
for(var i=0;i<cityText.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            alink 
+='<br />'+ cityText[i].replace('href="list.asp','target=_blank href="http://cncxp.cqwin.com/list.asp');
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
//document.all("city").innerHTML=cityText[2];
InBlock.gif
        //document.all("city").innerHTML=alink;
InBlock.gif
        InsertHtml(alink);
InBlock.gif        
InBlock.gif        document.getElementById('pagestart').value 
= parseInt(document.getElementById('pagestart').value,10)+1;
InBlock.gif        xmlhttp 
= null;
InBlock.gif        GetWeather();
ExpandedSubBlockEnd.gif     }

InBlock.gif     
else
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif             window.status 
= '出现错误:'+ xmlhttp.statusText+"  "+xmlhttp.status;
InBlock.gif             xmlhttp 
= null;
InBlock.gif            window.setTimeout(GetWeather,
10000);
InBlock.gif       
ExpandedSubBlockEnd.gif     }

InBlock.gif     
//xmlhttp = null;
ExpandedSubBlockEnd.gif
   }

InBlock.gif
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif
None.gif
</script>
ExpandedBlockStart.gifContractedBlock.gif        
<script language="vbscript">dot.gif 
InBlock.gif        
<!--
InBlock.gif            
Function bytes2BSTR(vIn) 
InBlock.gif                strReturn 
= "" 
InBlock.gif                
For i = 1 To LenB(vIn) 
InBlock.gif                    ThisCharCode 
= AscB(MidB(vIn,i,1)) 
InBlock.gif                    
If ThisCharCode < &H80 Then 
InBlock.gif                        strReturn 
= strReturn & Chr(ThisCharCode) 
InBlock.gif                    
Else 
InBlock.gif                        NextCharCode 
= AscB(MidB(vIn,i+1,1)) 
InBlock.gif                        strReturn 
= strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode)) 
InBlock.gif                        i 
= i + 1 
InBlock.gif                    
End If 
InBlock.gif                
Next 
InBlock.gif                bytes2BSTR 
= strReturn 
InBlock.gif            
End Function 
InBlock.gif            
-->
ExpandedBlockEnd.gif        
</script>
None.gif
</BODY>
None.gif
</HTML>
None.gif

转载于:https://www.cnblogs.com/Pharaoh/archive/2006/03/21/354713.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用AJAX获取下拉列表的选项。具体步骤如下: 1. 创建一个XMLHttpRequest对象: ```javascript var xhr = new XMLHttpRequest(); ``` 2. 设置`onreadystatechange`事件处理程序,监听AJAX请求的状态变化: ```javascript xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { // 请求成功,处理返回的数据 var response = JSON.parse(xhr.responseText); // 更新下拉列表的选项 updateDropdown(response); } else { // 请求失败,处理错误 console.log('AJAX请求失败'); } } }; ``` 3. 发送AJAX请求: ```javascript xhr.open('GET', '获取下拉列表选项的URL', true); xhr.send(); ``` 4. 编写`updateDropdown`函数来更新下拉列表的选项: ```javascript function updateDropdown(response) { var dropdown = document.getElementById('dropdown'); // 根据下拉列表的ID获取元素 dropdown.innerHTML = ''; // 清空原有的选项 for (var i = 0; i < response.length; i++) { var option = document.createElement('option'); // 创建一个选项元素 option.value = response[i].value; // 设置选项的值 option.textContent = response[i].text; // 设置选项的显示文本 dropdown.appendChild(option); // 添加选项到下拉列表中 } } ``` 在上述代码中,你需要替换`获取下拉列表选项的URL`为实际的URL,该URL应返回一个包含下拉列表选项的JSON数据。你还需要将`dropdown`替换为实际的下拉列表元素的ID。 这样,当AJAX请求完成后,会将返回的数据解析为JSON格式,并使用`updateDropdown`函数更新下拉列表的选项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值