您的位置:首页 > Web前端 > JavaScript

asp与javascript进行Ajax应用

2011-10-10 11:35 274 查看
一、ASP例子:

function GetSms()

Dim HttpUrl,https,xml

HttpUrl = "http://mb345.com:999/WS/Get.aspx?CorpID=" & userid & "&Pwd=" & password

Set https = Server.CreateObject("MSXML2.XMLHTTP")

https.open "post", HttpUrl, False

https.setRequestHeader "Content-type", "application/x-www-form-urlencoded"

https.send '===这里还可以带参数

GetSms=bytes2BSTR(https.responseBody) '======除了https.responseBody还有https.responseXml,https.responseText

End function

二、js例子:

do_checkuser(document.frmLogin.dbid.value,document.frmLogin.txtLoginID.value,document.frmLogin.txtLogPass.value);

/*============================================Ajax=================================*/

function do_checkuser(DBID,LoginID,LogPass)

{

do_PostAjax("rtx_checkuser.asp?DBID="+DBID+"&txtLoginID="+LoginID+"&txtLogPass="+LogPass);

}

function do_PostAjax(url)//向url页面发出请求;

{

createXmlHttp();

xmlHttp.onreadystatechange=getAjax_Result;//回调函数

xmlHttp.open("post",url,true);

xmlHttp.setRequestHeader("Method", "post "+url+" HTTP/1.1");

xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

xmlHttp.send(null);

}

function getAjax_Result()//服务器响应本页面并从服务器带回xmlHttp.responseText;

{

if(xmlHttp.readystate==4)

{

if(xmlHttp.status==200)

{

var b=xmlHttp.responseText;

if(b=="true"){

document.frmLogin.AppId.value="<%=rtx_appid%>";

document.frmLogin.Account.value=document.frmLogin.txtLoginID.value;

document.frmLogin.Pwd.value=document.frmLogin.txtLogPass.value;

document.frmLogin.ReservedString0.value=document.frmLogin.DBID.value; //ReservedString0这些名称由RTX方定

document.frmLogin.submit();

}//====提交

else{alert("用户名或密码不对,不能保存");}

return;

/*

root = xmlHttp.responseXML.documentElement;

nodelist=root.childNodes;

for(i=0;i<nodelist.length;i++){

if(nodelist[i].nodeType==1){

var b=nodelist[i].attributes[0].value;

if(b=="true"){

document.frmLogin.AppId.value="<%=rtx_appid%>";

document.frmLogin.Account.value=document.frmLogin.txtLoginID.value;

document.frmLogin.Pwd.value=document.frmLogin.txtLogPass.value;

document.frmLogin.ReservedString0.value=document.frmLogin.DBID.value; //ReservedString0这些名称由RTX方定

document.frmLogin.submit();

}//====提交

else{alert("用户名或密码不对,不能保存");}

}

}*/

}

}

}

function createXmlHttp()

{

try

{

xmlHttp = new XMLHttpRequest();

}

catch (e1)

{

try

{

xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (e2)

{

xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

}

}

}

/*=========================================Ajax end=================================*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: