您的位置:首页 > 理论基础 > 计算机网络

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实现,这里不在累述~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐