javascript ajax擷取資訊功能代碼_AJAX相關

來源:互聯網
上載者:User
Client端代碼如下:
複製代碼 代碼如下:

<html>
<head>
<script language="javascript"><!--
function getit(){
if(document.getElementById("url").value==""){
alert("Enter url!");
return false;
}
if(document.getElementById("count").value==""){
alert("Enter count!");
return false;
}
if(document.getElementById("num").value==""){
alert("Enter num!");
return false;
}
if(document.getElementById("end").value==""){
alert("Enter end!");
return false;
}
var url=document.getElementById("url").value;
var count=document.getElementById("count").value;
var num=document.getElementById("num").value;
var end=document.getElementById("end").value;
sendCall(url,count,num,end);
}
function sendCall(url,count,num,end) {
if (parseInt(num)>=parseInt(end)){return false;}
var nurl=url+"?count="+count+"&num="+num;
//alert(nurl);
//window.open(nurl);
var xmlHttp;
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
//解決FF中跨域問題
try{
netscape.security.PrivilegeManager.enablePrivilege( "UniversalBrowserRead ");
} catch (e) {
alert( "Permission UniversalBrowserRead denied. ");
}
}

xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status ==200){
var str = xmlHttp.responseText;
var msg=document.getElementById("getmsg");
if(str.match(/thereisnothing/)) {
msg.innerHTML = "資料已經完成傳輸!"
}else{
//msg.innerHTML =str;
write(str,count,num);
var next=parseInt(num)+parseInt(count);
sendCall(url,count,next,end);
}
}
}

xmlHttp.open('POST', nurl, true);
//xmlHttp.setRequestHeader("Content-Type", "text/xml");
//xmlHttp.setRequestHeader("charset", "utf-8");
xmlHttp.send(null);
}
function write(str,count,num){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var end = parseInt(num)+parseInt(count);
var name = "e:\\"+num+"-"+end+".txt";
var a = fso.CreateTextFile(name, true);
a.WriteLine(str);
a.Close();
//alert("我已經在你的E盤根目錄下產生了一個"+name+"的檔案!");
document.getElementById("num").value=end;
var msg=document.getElementById("getmsg");
msg.innerHTML="我已經在你的E盤根目錄下產生了一個"+name+"的檔案!";
}
// -->
</script>
</head>
<body>

<div>
Enter the setup then get the info:
</div>

<input id="url" value="http://www.oldjun.com/test.asp" size="50">
<input type=button value="開始" onclick="javascript:getit();"><br><br>
<div id="getmsg">
</div>

<br><br>
→ how many once:<input name="count" id="count" type="text" value="1000" size="30" /><br><br>
→ begin num :<input name="num" id="num" type="text" value="0" size="30" /><br><br>
→ end num :<input name="end" id="end" type="text" value="100" size="30" /><br><br>
</body></html>

功能可以改進,改進以後防止網路擁堵導致的擷取資訊失敗而造成的不連續,可以改進成實現很多功能的工具,比如刷票...自己發揮,我只提供思路~
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.