asp与javascript进行Ajax应用

 

一、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=================================*/

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值