Dec
17

The ajax to get the info what you need

本文提供一个思路,通过客户端与服务端获取信息,具体什么意思大家自己琢磨,本文只提供Client端代码,Server端代码自己去写,什么语言均可以!

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>

功能可以改进,改进以后防止网络拥堵导致的获取信息失败而造成的不连续,可以改进成实现很多功能的工具,比如刷票...自己发挥,我只提供思路~

共有4条评论

  1. fei: Jan,5th,2009

    菜鸟,经过,看看。希望能交个朋友

  2. summit: Jan,13th,2009

    现在的浏览器还支持js脚本写硬盘?那就不就可以。。。

    貌似不支持了,好像

  3. oldjun: Jan,16th,2009

    本地自然支持!

  4. 高尚爱卑鄙: Jul,31st,2009

    纯粹新手一个
    虽然不懂是什么但还是收藏了。不知是否允许?
    一心只想向牛者学习
    QQ502693161

NAME:

required

E-MAIL:

required, will not be published

HOMEPAGE:

CONTENT: