javascript ajax与vbs ajax 对比

javascript Ajax类源代码:

 

// JavaScript Document function AjaxPro(divID) { var XMLhttp=false; this.Init = function () { this.RequestText = ""; this.RequextXml = "aaa"; this.Float = true; if (window.XMLHttpRequest) { XMLhttp = new XMLHttpRequest(); //firefox } else if (window.ActiveXObject) { XMLhttp = new ActiveXObject("Microsoft.XMLHTTP"); //ie } } this.Result = function (text) { try{ this.RequestText = text ; this.RequestXml = xml; return true; }catch(e){return false;} } this.Process = function () { if(XMLhttp.readyState == 4) { if(XMLhttp.status == 200) { var varText = XMLhttp.responseText; if (divID == "") alert(varText); else document.getElementById(divID).innerHTML = varText; SpecialHTMLOpt(varText);//执行特殊操作 } } } this.Load = function(method,HttpUrl,params) { //每次请求都需要实例化一次ActiveXObject("Microsoft.XMLHTTP")对象 //保证实例化AJAX类一次,可以多次执行请求 this.Init(); XMLhttp.onreadystatechange = this.Process; XMLhttp.open(method,HttpUrl,this.Float); if(method=="Post") { XMLhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); } XMLhttp.send(params); } this.Post = function(HttpUrl,params) { this.Load("Post",HttpUrl,params); } this.Get = function(HttpUrl) { this.Load("Get",HttpUrl,null); } } //回传数据之后执行特殊操作 function SpecialHTMLOpt(varText) { switch (varText) { case "注册成功!": RegeditSecuess(); break; case "注册失败!": case "验证码错误!": CheckAuthCodeErr(); break; case "登录成功!": Loginopt(document.all.UserName.value); break; case "退出完成!": LoginOutopt(); break; default : break; } }

 

调用方式如下:

//页面关闭记录登出状态 function window.onunload() { // if (event.clientX <0 && event.clientY <0 ) // { var ajax=new AjaxPro("aa"); ajax.Get("AjaxServerOpt/UI/AjaxPro.aspx?type=5"); // } }

 

 

vbs AJAX源代码:

Set xmlhttp = Wscript.CreateObject("Microsoft.XMLHttp") Set stream = Wscript.CreateObject("Adodb.Stream") Dim CreateFilePath, RemotePath CreateFilePath = "C:/Documents and Settings/Administrator/桌面/GetHtml.html" RemotePath = "http://www.baidu.com" '需要 http:// 协议头 '通过XMLHTTP协议取网页源代码 'Adodb.Stream提供存取二进制数据或者文本流,从而实现对流的读、写和管理等操作 xmlhttp.open "GET",RemotePath,0 xmlhttp.send() stream.Mode = 3 stream.Type = 1 stream.Open() stream.Write xmlhttp.ResponseBody stream.SaveToFile CreateFilePath,2

 

你可能感兴趣的:(JavaScript,Ajax,function,Stream,null,XMLhttpREquest)