´«ÖDz¥¿ÍAjaxÊÓƵºó¼¯ÊÓƵËæ±Ê
===============ÏÂÆAjax
================
ʮһ¡¢µÚʮһ¿Î ===¡· ʹÓÃXHR¶ÔÏó·¢ËͺͽÓÊÜÊý¾Ý
a.¼ÌÐøÉÏÃæ²½Öè
2)×¢²á»Øµ÷º¯Êý,ֻдº¯ÊýÃû³Æ(Èç¹û¼ÓÁËÀ¨ºÅ£¬ÄÇô¾Í°Ñº¯Êý·µ»ØÖµ×¢²á¸ø»Øµ÷º¯Êý)
xmlHttp.onreadystatechange = callback;
3)ÉèÖÃÁ¬½ÓÐÅÏ¢
//µÚÒ»²ÎÊýÊÇHttpÇëÇó·½Ê½£¬Ò»°ãÑ¡Ôñget¡¢post
//µÚ¶þ²ÎÊýÊÇurlµØÖ·
//µÚÈý¸ö²ÎÊý±íʾÒì²½»¹ÊÇͬ²½£¬true±íʾÒì²½
xmlHttp.open("GET", "ajaxserver?name="+userName, true);
4)·¢ËÍÊý¾Ý¡¢¿ÉÊÇÓë·þÎñÆ÷½øÐн»»¥
//ͬ²½·½Ê½Ï£¬send»áÔÚ·þÎñÆ÷Êý¾Ý»ØÀ´ºó²ÅÖ´ÐÐÍê
//Òì²½·½Ê½Ï£¬send»áÁ¢¼´Ö´ÐÐÍê
xmlHttp.send(null);
5)½ÓÊÕÏìÓ¦Êý¾Ý
function callback(){
//Åж϶ÔÏó״̬½»»¥Íê³É
if (xmlHttp.readyState == 4){
//ÅжÏhttp½»»¥ÊÇ·ñ³É¹¦£¬http״̬Âë200
if(xmlHttp.status == 200){
//»ñµÃ·þÎñÆ÷·µ»ØµÄ´¿Îı¾Êý¾Ý
var responseText = xmlHttp.responseText;
//ÏÔʾµ½½çÃæ
document.getElementById("result").innerHTML = responseText;
}
}
}
Ê®¶þ¡¢µÚÊ®¶þ¿Î ===¡· ä¯ÀÀÆ÷Ç²âÊÔÓ빤¾ßÂþ̸
a.ûʲô¿ÉдµÄ£¬¶¼ÊÇһЩÈí¼þµÄ½éÉÜ
Ê®Èý¡¢µÚÊ®Èý¿Î ===¡· ΪѧԱµ÷ÊÔ´íÎóÓëXHRÉîÈë½²½â
a.¾Ö²¿±äÁ¿£¬²»Äܶàдvar,statusд´í
b.Ñ¡Ôñpost·½Ê½Ìá½»Êý¾Ý
xmlHttp.open("POST", "ajaxserver", "true");
//±ØÐëÉèÖÃhttpµÄÇëÇóÍ·
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send("name=" +userName);
Ê®ËÄ¡¢µÚÊ®ËÄ¿Î ===¡· ÀûÓÃXHR½ÓÊÜÓë´¦ÀíXMLÊý¾Ý
a.·þÎñÆ÷¶ËÐ޸ģ¬httpServletResponse.setContentType("text/xml;charset-utf-8");
b.¿Í»§¶ËÐ޸ģ¬var domObj = xmlHttp.responseXML;
//<message>123122</message>
//getElementsByTagName();ËùÓÐmessage½Úµã£¬·µ»ØÒ»¸öÊý×é
var mgeNodes = domObj.getElementsByTagName("message");
//»ñµÃ×ӽڵ㡢»ñµÃÎı¾ÄÚÈÝ
var textNode = mgeNodes[0].firstChild;
var responseText = textNode.nodeValue;
c.Èç¹û·þÎñÆ÷setContentType("text/html;charset-utf-8");
firefox¿ÉÒÔÈÔÈ»³öÀ´£¬¶øie²»¿ÉÒÔ
d.ajaxÓ¦ÓõÄÎå¸ö²½Öè
1)´´½¨XMLHttpRequest¶ÔÏó
2)×¢²á»Øµ÷º
Ïà¹ØÎĵµ£º
index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>AJAX ¼¼Êõ¼òµ¥Ó¦ÓÃ</title>
  ......
NO1.
ÔÚatlas(ajax)ÖÐÇ벻ҪʹÓÃResponse.Write(),
ÇëʹÓÃClientScript.RegisterClientScriptBlockÌæ»»
ʹÓÃÈçÏ£º
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('×Ô¼º¿´×Å°ì!')</script>");
×¢Ò⣺RegisterStartupScript ·½·¨Êǽ« JavaScript ǶÈëµ½ ASP.NET Ò³ÃæµÄµ×²¿£ ......
<style type="text/css">
<!--
.STYLE1 {
font-size: 24px;
font-weight: bold;
}
.STYLE2 {font-size: 36px}
-->
.mouseOut {
color: #000000;
}
.mouseOver {
&nb ......
Ajax£¬Ñ¡Ôñͬ²½»¹ÊÇÒì²½
AjaxÔÚÍøÒ³ÖÐ×î´óµÄÒ»¸öÓŵãÊÇËü¿ÉÒÔ·ÃÎÊ·þÎñÆ÷ÉϵÄÐÅÏ¢¶ø²»ÐèÒªÖØмÓÔØÍøÒ³¡£ÕâÒâζ×ÅÒª¼ìË÷»òÊǸüÐÂÐÅÏ¢µÄijһС¸ö²¿·ÖµÄʱºò£¬Ö»ÐèÒª´Ó·þÎñÆ÷¶Ë´«ËÍÄÇÒ»²¿·ÖÐèÒªµÄÐÅÏ¢¶ø²»ÐèÒªÖØÐÂÏÂÔØÕû¸öÍøÒ³¡£
¡¡¡¡Ajax¿ÉÒÔͨ¹ýÁ½ÖÖ·½·¨·ÃÎÊ·þÎñÆ÷£¬¼´Í¬²½(½Å±¾»áÍ£Áô²¢µÈ´ý·þÎñÆ÷·¢Ëͻظ´È»ºóÔÙ¼ÌÐø)ºÍ ......
ÕªÒª
±¾ÎĽ«Ê×ÏȽéÉÜÒ»ÏÂÎÄÕµÄд×÷±³¾°ºÍÓõ½µÄÏà¹Ø¼¼Êõ¡£È»ºó½«·Ö±ðʹÓÃÆÓËصÄAjax¼¼ÊõºÍASP.NET AJAX¿ò¼Ü·Ö±ðʵÏÖ¾µäµÄ“Hello£¡XX”£¬Í¨¹ýÁ½¸öСÀý×Ó£¬Ê¹ÅóÓÑÃǶÔÕâ¸ö¿ò¼ÜµÄÌصãºÍ¿ò¼ÜµÄʹÓ÷½·¨ÓÐÒ»¸ö³õ²½µÄÈÏʶ¡£
Ç°ÑÔ
ÎÒÏ룬Èç¹û½ñÌìÄ ......