À´Ô´£ºhttp://developer.51cto.com/art/200906/129502.htm
±¾ÎĽéÉÜÁËËÄÖÖÁ÷ÐеÄAJAX¿ò¼Ü£¬°üÀ¨¼ò½àµÄjQuery£¬ÃæÏò¶ÔÏóµÄ
Mootools£¬ÓµÓÐÇ¿´óÖ§³ÖµÄDojo£¬ÒÔ¼°×é¼þ»¯£¬RIA»¯µÄExt JS¡£
AJAX
ÊÇweb20
µÄ»ùʯ£¬ÏÖÔÚÍøÉÏÁ÷Ðм¸ÖÖ¿ªÔ´µÄ
AJAX¿ò¼Ü£¬±ÈÈ磺jQuery,Mootools,Dojo,Ext JSµÈµÈ£¬ÄÇôÎÒÃǵ½µ×ÔÚʲôÇé¿öϸÃʹÓÃÄǸö¿ò¼Ü£¿ÒÔÏÂÊÇÒ»×éÕª³µÄÊý¾Ý£º
AjaxianÔÚ2007Äêµ×¶ÔAjax¹¤¾ß½øÐÐÁ˵÷²é£¬²¿·Öµ÷²é½á¹û¼ûÏÂ±í£¨ÆäÖÐÊý×ÖΪµ÷²éÕßʹÓøù¤¾ßµÄ°Ù·Ö±È£¬ÏêϸµÄÇë²Î¼ûÍøÒ³£©£ºhttp://ajaxian.com/archives/2007-ajax-tools-usage-survey-results
Prototype
jQuery
Ext
Script.aculo.us
Mootools
YUI
JSON
Dojo
Backbase
34.1%
29.3%
22.5%
22.3%
14.3%
13%
12.9%
11.8%
8.3%
ÆäÖÐPrototypeʹÓÃÂÊ×î¸ß£¬ºÜ´ó³Ì¶ÈÉÏÊÇÒòΪËüÊÇ×îÔç³ÉÊìµÄ¿ò¼Ü£¬ºÜ¶àÒÔÇ°ÔÚÏîÄ¿ÖвÉÓã¬ËùÒÔÏÖÔÚÒ»Ö±ÔÚÓÃ
ÈÃÎÒÃÇÀ´¿´¿´Ñ¡ÔñAJAX¿ò¼ÜµÄ»ù´¡£º
ÄãµÄÏîÄ¿ÐèÇ󣨼´ÄãÐèÒªÄÄЩÌØÐÔ£¬ÀýÈçÊÇ·ñÒªÇó×ö³ö¾«ÃÀµÄ½çÃæ¡¢ÌØЧ»òÆäËü¹¦ÄÜ£©
ÊÇ·ñÖ§³ÖAµÈ¼¶µÄä¯ÀÀÆ÷£¨IE, FirefoxµÈ£©?
ÎĵµµÄÖÊÁ¿£ºÊÇ·ñÍêÉÆ£¨°üº¬½Ì³Ì£¬API£¬´úÂëʾÀýµÈ£©
¿ò¼ÜµÄ¿ÉÀ©Õ¹ÐÔÈçºÎ£¿Îª¿ò¼Üд²å¼þÈÝÒ×Âð£¿
......
//ƽ³£µ÷ÓÃjavascript·½·¨
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert'Weclome!!!');</script>");
±³¾°²»Îª°×É«µÄ·½·¨£º
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('Ìí¼Óʧ°Ü£¬ÇëÁªÏµ¼¼ÊõÔ±£¡');</script>");
//¼ÓÈëajaxºóµ÷ÓÃjavascript·½·¨
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "", "alert('Weclome!!!');", true);
µÚÒ»¸ö²ÎÊýÊÇ´¥·¢´ËÌáʾ¿ò¿Õ¼äµÄID£¬µÚ¶þ¸ö²ÎÊýÀàÐÍ£¬µÚÈý¸ö²ÎÊýÊǽű¾Ãû×Ö£¨¿ÉÒÔΪ¿Õ£©£¬µÚËĸö²ÎÊýjavascript´úÂ룬¼ÇסÔÚ´ÎÎÞÐèÔÙÓÃscript±êÇ©£¬µÚÎå¸ö²ÎÊýÊÇ·ñÆôÓÃ.
Àý×Ó£º
bool b= tmaintainmanager.PMaintainUpdate(tmaintain);
if (b)
{
ScriptManager.RegisterClientScriptBlock(btnsave, this.GetType(), "", "alert('Ìá½»³É¹¦!' ......
//ƽ³£µ÷ÓÃjavascript·½·¨
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert'Weclome!!!');</script>");
±³¾°²»Îª°×É«µÄ·½·¨£º
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('Ìí¼Óʧ°Ü£¬ÇëÁªÏµ¼¼ÊõÔ±£¡');</script>");
//¼ÓÈëajaxºóµ÷ÓÃjavascript·½·¨
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "", "alert('Weclome!!!');", true);
µÚÒ»¸ö²ÎÊýÊÇ´¥·¢´ËÌáʾ¿ò¿Õ¼äµÄID£¬µÚ¶þ¸ö²ÎÊýÀàÐÍ£¬µÚÈý¸ö²ÎÊýÊǽű¾Ãû×Ö£¨¿ÉÒÔΪ¿Õ£©£¬µÚËĸö²ÎÊýjavascript´úÂ룬¼ÇסÔÚ´ÎÎÞÐèÔÙÓÃscript±êÇ©£¬µÚÎå¸ö²ÎÊýÊÇ·ñÆôÓÃ.
Àý×Ó£º
bool b= tmaintainmanager.PMaintainUpdate(tmaintain);
if (b)
{
ScriptManager.RegisterClientScriptBlock(btnsave, this.GetType(), "", "alert('Ìá½»³É¹¦!' ......
µ±ÏÂÊ¢ÐеÄAjax
ÏÖÔÚAjax¿ò¼ÜÊý²»Ê¤Êý£¬AjaxµÄ¹¦ÄÜҲ̫ÅÓ´óµÄÒÔÖÁÓÚËüÁ¬ËüµÄ¸¸±²Javascript¶¼´ø¶¯ÆðÀ´ÁË£¬¼ÇµÃÎÒ×î³õ½Ó´¥webµÄʱºòJavascript»¹Ã»µ½´ïÓÐÏÖÔڵĸ߶ȣ¬Èç½ñËæ×Å¿Í»§ÌáÐÑÔ½À´Ô½ÖØÒª£¬ºÜ¶àÈí¼þ¿ª·¢²¢²»½ö½öÍ£ÁôÔÚ¹¦ÄÜʵÏÖµÄÒªÇóÉÏ£¬¶øÊǸü×¢Öؽ»»¥¡¢·ÖÏíºÍ»¥¶¯£¨ÕâÒ²ÊÇweb2.0µÄÄ¿±ê£©¡£ÆäʵÕâÒ²ÊÇÍêÈ«ÕýÈ·µÄ£¬±Ï¾¹ÄÇÖÖ½ö½ö¸³Ó蹦ÄܵĶ«Î÷ÎÒÃDz»ÄÜÂú×ãÁË£¬ÀýÈçÄãÂò¶«Î÷»¹ÏëÒªÌôºÃ¿´µÄÄØ£¬ºÎ¿öÈí¼þ¿ª·¢ÄØ¡£»Øµ½ÕýÌ⣬Ajax¿ò¼ÜÎÒ»¹ÊÇÔÞ³ÉʹÓõģ¬±Ï¾¹×Ô¼ºÀ´ÊµÏÖЧÂÊÌ«ÂýÁË£¬ÏñÄ¿Ç°ÓÅÐãµÄjavascript¿ò¼ÜjQuery¾Í²»µÃ²»ÁîÈËÔÞÉÍ£¬¶øÇÒËüÒ²ÊÇÔ½À´Ô½ÊÜ»¶Ó£¬Á¬Î¢Èí¶¼ÔÚAsp.Net MVC¿ò¼ÜÖÐ×Ô´øÁËjQuery¡£µ«ÊÇÎÒ¾õ»¹ÊÇÓбØÒªÁ˽âAjaxµÄ±¾Öʵģ¬ÕâÑùÄã²ÅÄÜÔËÓÃ×ÔÈç¡£
Ajax
µÄ¹¤×÷
AjaxÖ±¾õÈÏʶ£ºÎÒÃÇ·¢ËÍÒ»¸öÇëÇ󣬵«ÊÇÕâ¸öÇëÇó±È½ÏÌØÊâËüÊÇÒì²½µÄ£¬Ò²¾ÍÊÇ˵¿Í»§¶ËÊDz»»á¸Ð¾õµ½µÄ¡£ÔÚ·¢ËÍÕâ¸öÇëÇóµÄʱºòÎÒÃÇ°ó¶¨ÁËÒ»¸öʼþ£¬Õâ¸öʼþ»á¼à¿ØÎÒÃÇ·¢ËÍÇëÇóµÄ״̬£¬²¢ÇÒÿ´Î״̬¸Ä±ä¶¼»á´¥·¢£¬ËùÒÔÎÒÃǾͿÉÒÔ¸ù¾Ý²»Í¬µÄ״̬ÈÃËûÖ´Ðв»Í¬µÄ²Ù×÷¡£ÇëÇóµ½´ï·þÎñÆ÷¶ËµÄºó·þÎñÆ÷¶Ë¸ù¾ÝÏàÓ¦µÄÇëÇó·µ»Ø ......
<script type="text/javascript" language="javascript" src="JS/jquery-1[1].2.3.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){ //Jquery Ò³Ãæ¼ÓÔØʼþ£¬µ±Ò³Ãæ¼ÓÔØÖ®ºóÊ×ÏÈÖ´ÐÐÕâ¸ö·½·¨
//µÚÒ»ÖÖAjaxÇëÇó
$.ajax({
type:"GET", //ÇëÇóÀàÐÍ£¬ÓÐget,postµÈÀàÐÍ£¬ºÍ±íµ¥Ìá½»ÊÇÒ»ÑùµÄ
url:"Result.aspx", //ÇëÇó´¦ÀíµÄÒ³Ãæ,¾ÍÊÇ˵ÓÉÄǸöÒ³Ã沶»ñÇëÇó£¬Í¬ÑùÕâ¸ö·¾¶¿ÉÒÔ»»³Éashx£¬Ò»°ã´¦Àí³ÌÐò
data: "name=John&location=Boston", //´«µÝ²ÎÊý£¬ÊµÔÚ¾ÍÊÇ(Result ......
Á˽âʹÓà ASP.NET AJAX ½øÐоֲ¿Ò³Ãæ¸üÐÂ
¼ò½é
MicrosoftµÄ ASP.NET ¼¼ÊõÌṩÁËÒ»¸öÃæÏò¶ÔÏó¡¢Ê¼þÇý¶¯µÄ±à³ÌÄ£ÐÍ£¬²¢½«ÆäÓëÒѱàÒë´úÂëµÄÓÅÊƽáºÏÆðÀ´¡£µ«Æä·þÎñÆ÷¶ËµÄ´¦ÀíÄ£ÐÍÈÔ´æÔÚ¼¼Êõ±¾ÉíËù¹ÌÓеļ¸µã²»×㣺
½øÐÐÒ³Ãæ¸üÐÂÐèÒªÍù·µ·þÎñÆ÷£¬Òò´ËÐèÒªÒ³ÃæˢУ»
À´»ØÍù·µ²»»á±£Áô Javascript »òÆäËû¿Í»§¶Ë¼¼Êõ£¨Èç Adobe Flash£©Éú³ÉµÄÈκÎЧ¹û¡£
Ôڻش«¹ý³ÌÖУ¬³ý Microsoft Internet Explorer Ö®ÍâµÄä¯ÀÀÆ÷¶¼²»Ö§³Ö×Ô¶¯´æ´¢¹ö¶¯Î»Ö᣶ø¼´Ê¹ÔÚInternet Explorer ÖУ¬Ò³ÃæË¢ÐÂʱÈÔÈ»»á³öÏÖÉÁÆÁÏÖÏó¡£
»Ø´«¿ÉÄܻᵼÖÂÕ¼Óý϶àµÄ´ø¿í£¬ÕâÊÇÒòΪ __VIEWSTATE ±íµ¥×ֶοÉÄÜ»á±ä´ó£¬ÓÈÆäÊÇÔÚ´¦Àí GridView »ò Repeater µÈ¿Ø¼þʱ¡£
ûÓÐͳһµÄÄ£ÐÍÓÃÓÚͨ¹ýJavaScript»òÆäËû¿Í»§¶Ë¼¼Êõ·ÃÎÊ Web ·þÎñ¡£
½øÈë Microsoft µÄ ASP.NET AJAX À©Õ¹¡£AJAX µÄÈ«³ÆΪ Asynchronous JavaScript And XML£¨Òì²½ JavaScript ºÍXML£©£¬ËüÊÇÒ»¸ö¼¯³É¿ò¼Ü£¬ÓÃÓÚͨ¹ý¿çƽ̨µÄJavaScript ÌṩÔöÁ¿Ò³Ãæ¸üС£AJAX °üÀ¨º¬ÓÐMicrosoft AJAX FrameworkµÄ·þÎñÆ÷²à´úÂ룬ÒÔ¼°Ò»¸öÃûΪ Microsoft AJAX Script Library µÄ½Å±¾×é¼þ¡£ASP.NET AJAX À©Õ¹»¹¿çƽ̨֧³Öͨ¹ýJavaScript ·ÃÎÊASP.NET Web · ......
Á˽âʹÓà ASP.NET AJAX ½øÐоֲ¿Ò³Ãæ¸üÐÂ
¼ò½é
MicrosoftµÄ ASP.NET ¼¼ÊõÌṩÁËÒ»¸öÃæÏò¶ÔÏó¡¢Ê¼þÇý¶¯µÄ±à³ÌÄ£ÐÍ£¬²¢½«ÆäÓëÒѱàÒë´úÂëµÄÓÅÊƽáºÏÆðÀ´¡£µ«Æä·þÎñÆ÷¶ËµÄ´¦ÀíÄ£ÐÍÈÔ´æÔÚ¼¼Êõ±¾ÉíËù¹ÌÓеļ¸µã²»×㣺
½øÐÐÒ³Ãæ¸üÐÂÐèÒªÍù·µ·þÎñÆ÷£¬Òò´ËÐèÒªÒ³ÃæˢУ»
À´»ØÍù·µ²»»á±£Áô Javascript »òÆäËû¿Í»§¶Ë¼¼Êõ£¨Èç Adobe Flash£©Éú³ÉµÄÈκÎЧ¹û¡£
Ôڻش«¹ý³ÌÖУ¬³ý Microsoft Internet Explorer Ö®ÍâµÄä¯ÀÀÆ÷¶¼²»Ö§³Ö×Ô¶¯´æ´¢¹ö¶¯Î»Ö᣶ø¼´Ê¹ÔÚInternet Explorer ÖУ¬Ò³ÃæË¢ÐÂʱÈÔÈ»»á³öÏÖÉÁÆÁÏÖÏó¡£
»Ø´«¿ÉÄܻᵼÖÂÕ¼Óý϶àµÄ´ø¿í£¬ÕâÊÇÒòΪ __VIEWSTATE ±íµ¥×ֶοÉÄÜ»á±ä´ó£¬ÓÈÆäÊÇÔÚ´¦Àí GridView »ò Repeater µÈ¿Ø¼þʱ¡£
ûÓÐͳһµÄÄ£ÐÍÓÃÓÚͨ¹ýJavaScript»òÆäËû¿Í»§¶Ë¼¼Êõ·ÃÎÊ Web ·þÎñ¡£
½øÈë Microsoft µÄ ASP.NET AJAX À©Õ¹¡£AJAX µÄÈ«³ÆΪ Asynchronous JavaScript And XML£¨Òì²½ JavaScript ºÍXML£©£¬ËüÊÇÒ»¸ö¼¯³É¿ò¼Ü£¬ÓÃÓÚͨ¹ý¿çƽ̨µÄJavaScript ÌṩÔöÁ¿Ò³Ãæ¸üС£AJAX °üÀ¨º¬ÓÐMicrosoft AJAX FrameworkµÄ·þÎñÆ÷²à´úÂ룬ÒÔ¼°Ò»¸öÃûΪ Microsoft AJAX Script Library µÄ½Å±¾×é¼þ¡£ASP.NET AJAX À©Õ¹»¹¿çƽ̨֧³Öͨ¹ýJavaScript ·ÃÎÊASP.NET Web · ......
ʹÓÃDWR¿ª·¢AjaxÓ¦Óãº
1¡¢µ¼ÈëDWRµÄJar°ü£ºdwr.jar;
2¡¢ÔÚ/WEB-INFÏÂÌí¼Ódwr.xmlÅäÖÃÎļþ£»
3¡¢ÔÚweb.xmlÎļþÖÐÅäÖÃdwrµÄ·þÎñÆ÷¶Ë×é¼þ£¨DwrServlet£©:
<!-- Ìí¼ÓDWRµÄServlet -->
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
4¡¢´´½¨JavaScriptµ÷ÓõķþÎñÆ÷¶Ë×é¼þ£¬¿ÉÒÔÊÇÒ»¸öÆÕͨµÄJavaÀࣻ
5¡¢¶Ôdwr.xmlÎļþ½øÐÐÅäÖÃ;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://getahead.org/dwr/dwr20.dtd">
<dwr> ......