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=================================*/
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=================================*/
相关文章推荐
- ASP和AJAX应用一例,检测注册用户是否有效
- 简单ASP.NET AJAX 客户端应用:用JS直接调用WebServices方法
- 《ASP.NET AJAX 应用剖析立即上手》推荐序!
- 异步上传文件插件AjaxFileUploader在Asp.net MVC中应用
- Ajax基础应用入门02(结合javascript)
- 原生javascript实现Ajax和jQuery实现Ajax实例应用
- Ajax在asp.net上的基本应用
- ASP.Net 如何在UpdatePanel (ajax)更新后执行Javascript
- 使用Javascript,CSS和Ajax创建ASP.NET自定义控件
- ASP.Net中应用Javascript的示例(引)
- 使用Javascript,CSS和Ajax创建ASP.NET自定义控件
- ASP.NET AJAX学习记要(2)-下手之JavaScript
- Asp.net Ajax:我可以用javascript做些什么?
- Asp.net Ajax:我可以用javascript做些什么?
- ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- Ajax简单应用(asp.net)
- ASP.Net WebAPI与Ajax进行跨域数据交互时Cookies数据的传递
- 针对ASP.NET页面实时进行GZIP压缩优化的几款压缩模块的使用简介及应用测试!(附源码)
- ASP.Net WebAPI与Ajax进行跨域数据交互时Cookies数据的传递
- ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化