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² ......
ÔÚʹÓÃjQuery µÄAjax¼ÓÔØÊý¾ÝÊÇ Èç¹ûʹÓÃget·½Ê½´«µÝ²ÎÊýÔò´æÔÚÒ»ÏÂÎÊÌâ
firefoxÏ´«µÝÊý¾ÝÕý³£
ieÏÂÔò»á³öÏÖ»º´æÎÊÌâ
½â¾ö·½·¨£º
1¡¢http://yourwebsite?parseInt(Math.random() * 1000) ÔÚurlºóÃæ¼ÓÉÏÒ»¸öËæ¼´Êý£¬ÕâÑùÿ´Î·¢Ë͵ľͲ»Ò»ÑùÁË£¬¶øÇÒ²»Ó°ÏìÄãµÄ¹¦ÄÜ.
2¡¢Ê¹ÓÃpost´«µÝ²ÎÊý
......
ÔÚC#ÖÐ
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;
using System.Collections;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.Ba ......
/*ÔÚÓÐÖÐÎIJÎÊýʱ,½ÓÊÕ·½ÐèҪʹÓÃUTF-8·½Ê½¶ÔÊý¾Ý½øÐнâÂë
*²»Ö§³Öpost¸½¼þ
*/
function getXmlHttpRequest() {
var xmlHttpRequest = null;
try {
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} ......
ÔÚ¡¶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 ......