AJAXÖÐÎÄÎÊÌâ[ת]
AJAXÖÐÎÄÎÊÌâ·ÖΪÁ½´óÀࣺ
1£©·¢ËÍ·¾¶ÖеIJÎÊýÓÐÖÐÎÄ£¬ÔÚ·þÎñÆ÷¶Î½ÓÊÕ²ÎÊýÖµÊÇÂÒÂë
ÀýÈ磺
var url="a.jsp?name=СÀî"£»
xmlHTTP.open ("post",url,true);
½â¾ö°ì·¨£º
ÀûÓÃjavascriptµÄÌṩµÄescape()»òencodeURI()·½·¨
ÀýÈ磺
¿Í»§¶Ë£º
var url="a.jsp?name=СÀî"£»
url=encodeURI(url);
url=encodeURI(url); //Á½´Î£¬ºÜ¹Ø¼ü[¾ßÌåΪʲô£¬ÎÒÒ²²»Çå³þ]
/********************************************/
Ò²ÓÐÈËд³Évar url="a.jsp?name=escape("СÀî")"£»
¹¦ÄܺÍencodeURI·½·¨ÀàËÆ¡£
/********************************************/
xmlHTTP.setrequestheader("cache-control","no-cache");
xmlHTTP.setrequestheader("Content-Type","application/x-www-form-urlencoded");
xmlHTTP.setrequestheader("contentType","text/html;charset=uft-8")//Ö¸¶¨·¢ËÍÊý¾ÝµÄ±àÂë¸ñʽ
xmlHTTP.open ("post",url,true);
·þÎñÆ÷¶Ë£º
String name = request.getParameter("name");
name = java.net.URLDecoder.decode("name", "UTF-8");
2£©·µ»ØÀ´µÄresponseText»òresponseXMLµÄÖµÖк¬ÓÐÖÐÎÄÊÇÂÒÂë
ÔÒò£ºAJAXÔÚ½ÓÊÕresponseText»òresponseXMLµÄÖµµÄʱºòÊÇ°´ÕÕUTF-8µÄ¸ñʽÀ´½âÂëµÄ£¬Èç¹û·þÎñÆ÷¶Î·¢Ë͵ÄÊý¾Ý²»ÊÇUTF-8µÄ¸ñʽ£¬ÄÇô½ÓÊÕresponseText»òresponseXMLµÄÖµÓпÉÄÜΪÂÒÂë¡£
½â¾ö°ì·¨£ºÔÚ·þÎñÆ÷Ö¸¶¨·¢ËÍÊý¾ÝµÄ¸ñʽ£º
ÔÚjspÎļþÖУº
response.setContentType("text/text;charset=UTF-8");//·µ»ØµÄÊÇtxtÎı¾Îļþ
»òÊÇ
response.setContentType("text/xml;charset=UTF-8");//·µ»ØµÄxmlÎļþ
×ܽá:1)ajaxÌá½»Êý¾ÝµÄ¸ñʽĬÈÏΪutf-8,ÀûÓÃjavascriptµÄÌṩµÄescape()»òencodeURI()·½·¨.ÔÚ·þÎñÆ÷¶Ë½ÓÊÕµÄʱºòҪʹÓÃjava.net.URLDecoder.decode("","UTF-8")·½·¨½øÐнâÂë.
2)xtmlhttp ·µ»ØµÄÊý¾ÝĬÈϵÄ×Ö·û±àÂëÊÇutf-8,ËùÒÔ·þÎñÆ÷ÒªÏò¿Í»§¶Ë·¢ËÍÊý¾ÝµÄʱºò,Ò²Òª²ÉÓÃutf-8±àÂë
Èç¹ûÉÏÊö·½·¨ÈÔÈ»½â¾ö²»ÁËÂÒÂëÎÊÌâ,ÄÇÄã³¢ÊÔһϰÑjsp,htm,javaÎļþÓÃUTF-8±àÂë¸ñʽ±£´æ.
×ÜÖ®:Ç°ºǫ́Êý¾Ý½»»¥¶¼²ÉÓÃutf-8±àÂë¾ÍÐÐÁË.
Ïà¹ØÎĵµ£º
Õâ¸öÀàÕª×Ô£º ASP.NET AjaxµäÐÍÓ¦Óà һÊé
xmlhttp.js
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
elem ......
B/SΪºÎÄÑÓÚÌṩºÃµÄÓû§½»»¥ÌåÑé?
×î´óÎÊÌâÓм¸¸ö£º
¡¡¡¡(1)ÎÞ״̬µÄHTTPÐÒé
¡¡¡¡WINDOWS´°Ìå¼äÄܹ»Í¨¹ýÄÚ´æÖ±½Ó½»»»ÐÅÏ¢£¬µ«×÷ΪB/S¼Ü¹¹Í¨Ñ¶»ù´¡ÐÒéµÄHTTPÊÇÎÞ״̬µÄ¡£
¡¡¡¡Èç¹û½«ä¯ÀÀÆ÷¿´³ÉÊÇ¿ÍÈË£¬Web·þÎñÆ÷¿´³ÉÊÇÂùݣ¬ÔÚHTTPÐÒéµÄ¹ÜÀí֮ϣ¬»á³öÏÖÕâÖÖÇé¿ö£º²»¹Üij¿ÍÈËÀ´·Ã¶àÉٴΣ¬Web·þÎñÆ÷¶¼½«ÆäÊÓΪµ ......
ÈçºÎÔÚ¿Í»§¶ËÖ±½Óµ÷ÓÃWebServiceÖеķ½·¨£¿
ÕâÀï½áºÏ¾Ñé×Ô¼ºÐ´Ò»Ð´
1.Ê×ÏÈн¨Ò»¸ö ASP.NET AJAX-Enabled Web Site,ÕâÑùϵͳΪÎÒÃÇ×Ô¶¯ÅäÖúÃÁË»·¾³£¬ÕâÖ÷ÒªÌåÏÖÔÚWeb.configÕâ¸öÎļþÉÏ£¬Èç¹ûÒÑÓÐÍøÕ¾²»ÊÇASP.NET AJAX-Enabled Web SiteÒ²¿ÉÒÔ¶ÔÕÕÐÞ¸ÄÏÂWeb.config£¬Ò²¿ÉÒÔ´ïµ½ÏàͬµÄЧ¹û¡£
2.н¨Ò»¸öweb·þÎñ£¬WebSer ......
½ñÌìÔçÉÏÀÏÙ¡½«×òÌìµÄÁ·Ï°½øÐÐÁ˽²½â¡£½ñÌìµÄÖ÷ÒªÄÚÈÝÊǶÔAJAXµÄ»ã×ÜÁ·Ï°£¬×öÁËÁ½¸öÁ·Ï°¶¼ÊDZȽϳ£Ê¹ÓõÄÓ¦Óá£
Ò»¡¢ ÏÂÀ¿òµÄ¼¶Áª£¬±ÈÈ磬ѡÔñÏÂÀ¿òÒ»ÖеÄÄÚÈÝ£¨³ÇÊÐÃû³Æ£©£¬ÔÚÏÂÀ¿ò¶þÖÐÏÔʾÔÚÕâ¸ö³ÇÊÐÖеIJ¿ÃÅ¡£ÔÚÏÂÀ ......
¡¡Ò»°ãÇé¿öÏ£¬Ê¹ÓÃAjaxÌá½»µÄ²ÎÊý¶àÊÇЩ¼òµ¥µÄ×Ö·û´®£¬¿ÉÒÔÖ±½ÓʹÓÃGET·½·¨½«ÒªÌá½»µÄ²ÎÊýдµ½open·½·¨µÄurl²ÎÊýÖУ¬´Ëʱsend·½·¨µÄ²ÎÊýΪnull¡£
ÀýÈç £º
¡¡¡¡ var url = "login.jsp?user=XXX&pwd=XXX";
¡¡¡¡xmlHttpRequest.open("GET",url,true);
¡¡¡¡xmlHttpRequset.send(null);
¡¡¡¡´ËÍ⣠......