XMlHTTP ajax实现数据无刷新调用
2008-04-06 17:02
447 查看
实现功能:文本框失去焦点时,带出其他相关信息。
HTML:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>未命名頁面</title>
<script type ="text/javascript" language ="javascript" >...
var XmlHttp=false;
function AjaxSet()
...{
if (window.XMLHttpRequest)
...{
XmlHttp = new XMLHttpRequest;
}
else
...{
try
...{
XmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
...{
XmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
}
}
}
function AjaxSendServer()
...{
AjaxSet();
var UserID=document.getElementById("txtUserID").value;
var url="DAL.aspx?id="+UserID;
XmlHttp.onreadystatechange=updatepage;
XmlHttp.open("GET",url,true);
XmlHttp.send(null);
}
function updatepage()
...{
if(XmlHttp.readyState==4)
...{
if(XmlHttp.status==200)
...{
var reponse=XmlHttp.responseText.split(',');
document.getElementById("txtName").value=reponse[0];
document.getElementById("txtDepart").value=reponse[1];
XmlHttp=false;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type ="text" id="txtUserID" runat="server" onfocusout ="AjaxSendServer()" />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtDepart" runat="server"></asp:TextBox>
<asp:GridView ID="gvTest" runat="server" Width="483px" ></asp:GridView>
</div>
</form>
</body>
</html>
其中数据处理URL: DAL.aspx
protected void Page_Load(object sender, EventArgs e)
...{
if (Request.QueryString[0].ToString() == "F5400171")
...{
Service.WebService cDAL = new WebService();
string sql = "select username,departno from userinfor where userid='"+Request.QueryString[0].ToString()+"'";
string s =cDAL.GetStr(sql);
// string s = "jiaxin,MIS";
Response.Write(s);
Response.End();
}
}
其中的数据访问采用webservice实现,这里不在累述~
HTML:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>未命名頁面</title>
<script type ="text/javascript" language ="javascript" >...
var XmlHttp=false;
function AjaxSet()
...{
if (window.XMLHttpRequest)
...{
XmlHttp = new XMLHttpRequest;
}
else
...{
try
...{
XmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
...{
XmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
}
}
}
function AjaxSendServer()
...{
AjaxSet();
var UserID=document.getElementById("txtUserID").value;
var url="DAL.aspx?id="+UserID;
XmlHttp.onreadystatechange=updatepage;
XmlHttp.open("GET",url,true);
XmlHttp.send(null);
}
function updatepage()
...{
if(XmlHttp.readyState==4)
...{
if(XmlHttp.status==200)
...{
var reponse=XmlHttp.responseText.split(',');
document.getElementById("txtName").value=reponse[0];
document.getElementById("txtDepart").value=reponse[1];
XmlHttp=false;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type ="text" id="txtUserID" runat="server" onfocusout ="AjaxSendServer()" />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtDepart" runat="server"></asp:TextBox>
<asp:GridView ID="gvTest" runat="server" Width="483px" ></asp:GridView>
</div>
</form>
</body>
</html>
其中数据处理URL: DAL.aspx
protected void Page_Load(object sender, EventArgs e)
...{
if (Request.QueryString[0].ToString() == "F5400171")
...{
Service.WebService cDAL = new WebService();
string sql = "select username,departno from userinfor where userid='"+Request.QueryString[0].ToString()+"'";
string s =cDAL.GetStr(sql);
// string s = "jiaxin,MIS";
Response.Write(s);
Response.End();
}
}
其中的数据访问采用webservice实现,这里不在累述~
相关文章推荐
- 实现jquery.ajax及原生的XMLHttpRequest跨域调用WCF服务的方法
- 使用 XMLHttpRequest 实现 Ajax 四:调用 Webservice
- 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- 使用 XMLHttpRequest 实现 Ajax 二:取回 XML 数据
- 使用 XMLHttpRequest 实现 Ajax 三:取回 Json 数据
- 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
- Ajax处理XML,XMLHttpRequest对象的创建和访问servlet并返回xml数据到页面展示
- AJAX提交数据无刷新,“重量级”的实现:ModalUpdateProgress控件。
- XMLHttpRequest实现Ajax效果实例
- 利用XML数据绑定实现页面无刷新的数据浏览
- 【Ajax】XMLHttpRequest介绍以及在前端如何实现Ajax
- 在微信中调用ajax出现的问题,XMLHttpRequest对象没有初始化
- ajax XMLHttpRequest.readyState: 状态码 0 - (未初始化)还没有调用send()方法 解决了
- 如何使用XmlHttpRequest对象实现ajax?
- Ajax核心XMLHttpRequest对象、(发送请求、接收)方法和属性介绍、AJAX开发框架、数据格式提要(XML、JSON、HTML)
- XMLHTTP+javascript+Asp写得聊天室,无刷新实现
- Ajax核心XMLHttpRequest对象、(发送请求、接收)方法和属性介绍、AJAX开发框架、数据格式提要(XML、JSON、HTML)
- jQuery实现ajax跨域请求XML数据 并解析XML元素
- Google Maps API 2.0解析(15-GXslt和GXmlHttp实现AJAX)