javascript ajax获取信息功能代码

2016-02-19 10:41 5 1 收藏

在这个颜值当道,屌丝闪边的时代,拼不过颜值拼内涵,只有知识丰富才能提升一个人的内在气质和修养,所谓人丑就要多学习,今天图老师给大家分享javascript ajax获取信息功能代码,希望可以对大家能有小小的帮助。

【 tulaoshi.com - Web开发 】

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();"brbr
div id="getmsg"
/div

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

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

来源:https://www.tulaoshi.com/n/20160219/1595492.html

延伸阅读
标签: Web开发
代码如下: script type="text/javascript"!-- var request = false; try { request = new XMLHttpRequest(); } catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = false; } } }...
标签: Web开发
% Function BytesToBstr(body,Cset)     dim objstream     set objstream = Server.CreateObject("adodb.stream")     objstream.Type = 1     objstream.Mode =3     objstream.Open objstream.Write body   &n...
标签: Web开发
代码如下: html head title/title script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"/script script type="text/javascript" $(function(){ $("#siteName").blur(function(){ $.ajax({ type: "GET", url: "http://data.alexa.com/data/?cli=10&dat=snba&ver=7.0&url="+$("#siteName...
标签: Web开发
客户端代码mouseover.php 代码如下: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="http://www.w3.org/1999/xhtml" head meta http-equiv="Content-Type" content="text/html; charset=gb2312" / title鼠标悬浮测试/title /head script typ...
代码如下: StringBuilder phoneInfo = new StringBuilder(); phoneInfo.append("Product: " + android.os.Build.PRODUCT + System.getProperty("line.separator")); phoneInfo.append( "CPU_ABI: " + android.os.Build.CPU_ABI + System.getProperty("line.separator")); phoneInfo.append( "TAGS: " + android.os.Build.TAGS + System.ge...

经验教程

769

收藏

88
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部