AJAX DWR
ʹÓÃÔʼµÄXMLHttpRequest·¢³öÇëÇóʱ,Ö»ÄܶÔServletºÍJSP²Ù×÷
ÔÚJSPÖд´½¨3¸öfunction
1.createXmlHttpRequest----¸ºÔðÅжÏä¯ÀÀÆ÷ÀàÐÍ´´½¨ XMLHttpRequest¶ÔÏó
var xmlHttpRequest;
function createXMLHttpRequest(){
// IE ä¯ÀÀÆ÷
if(window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
// ·ÇIEä¯ÀÀÆ÷
return new XMLHttpRequest();
}
}
2.doLogin------¸ºÔð¸ü¼Ó´´½¨ºÃµÄXMLHttpRequest¶ÔÏó·¢³öÇëÇó
function doLogin(obj){
var url = "servlet/LoginServlet?userName="+obj.value;
// 1. ´´½¨XMLHttpRequest×é¼þ
xmlHttpRequest = createXMLHttpRequest();
// 2. ÉèÖûص÷º¯Êý
xmlHttpRequest.onreadystatechange = haoLeJiaoWo;
// 3. ³õʼ»¯XMLHttpRequest×é¼þ
// ʹÓÃget·½·¨µ÷ÓÃURL,true´ú±íÊÇÒì²½µÄ
xmlHttpRequest.open("GET",url,true);
// 4. ·¢ËÍÇëÇó
xmlHttpRequest.send(null);
alert("123");
}
3.haolejiaowo---¸ºÔð½øÐлص÷´¦Àí
function haoLeJiaoWo(){
// readyState-- =4±íʾµÃµ½ÁË·µ»Ø½á¹û
// status=200 ±íʾ³É¹¦¶øÇÒ²»³ö´í
/*
ÇëÇó״̬£º
0 -- δ³õʼ»¯
1 -- ³õʼ»¯
2 -- ·¢ËÍÇëÇó
3 -- ¿ªÊ¼½ÓÊܽá¹û
4 -- ½ÓÊܽá¹ûÍê±Ï
ÿ´Î״̬¸Ä±ä¶¼»áµ÷Õâ¸öº¯Êý
*/
if( xmlHttpRequest.readyState == 4 &
Ïà¹ØÎĵµ£º
APS.NETÒ¹»°µÄÀý×Ó¼ÓÔغ󱨴íÈçÏ£º
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35´íÎó
ÔÒòÊÇδÄܼÓÔØÎļþ»ò³ÌÐò¼¯ system.web.extensions
½â¾ö°ì·¨:
1,Èç¹ûÄãµÄ³ÌÐòÔËÐÐÔÚÄãÄÜ¿ØÖƵķþÎñÆ÷ÉÏ£¬ÄÇô°²×°asp.net ajax¾ÍÐÐÁË£¬ÕâÊÇSystem.Web.ExtensionsµÈdll×öΪGAC² ......
Ò³Ãæ´úÂ룺
<head runat="server">
<title>ÎÞ±êÌâÒ³</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManage ......
ÔÚ¡¶Pragmatic Ajax A Web 2.0 Primer ¡·ÖÐżȻ¿´µ½¶ÔreadyStae״̬µÄ½éÉÜ£¬¸Ð¾õÕâ¸ö½éÉܺÜʵÔÚ£¬ÕªÒëÈçÏ£º
0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire respons ......
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:updatepanel ID="UP" runat="server">
<ContentTemplate>
......