¥Ø«e¦bºô¸ô¤W³Ì±`³Q¥Î¨ìªº JavaScript framework¡A´N¬O prototype.js¡A¥i¥Ñ¤U¦Cºô§}¤U¸ü¡Ghttp://www.prototypejs.org ©Ò¿×ªº framework¡A¥i¥H¬Ý¦¨¬Oì¥ý JavaScript ªºÀ³¥Îµ{¦¡¤¶±¡]API¡A©Î¬O Appliation Program Interface¡^¡A¥i¥H®Ú°ò©ó°ò¥»ªº JavaScript ¨Ó´£¨Ñ§ó¥ý¶iªº¥\¯à¡C§ÚÌ¥»¤p¸`©Ò¥Îªº prototype.js ª©¥»¬O 1.5.1.1¡]2007/06/19 µo¦æ¡^¡A©Ò´£¨ÑªºÂX¥R¥\¯à¦p¤U¡G¦b«e¤@¤p¸`§Ṳ́w¸g»¡©ú¤F AJAX ªº°ò¥»¨Ï¥Î¤è¦¡¤Î½d¨Ò¡A¥»¤p¸`±N»¡©ú¦p¦ó¨Ï¥Î prototype.js ¨Ó¶i¦æ AJAX ªººô¶³]p¡Cº¥ý¡A§Ú̪½±µ¬Ý¬Ý¤@Ó²³æªº½d¨Ò¡G
- AJAX¡G´£¨Ñ¹ï©ó AJAX ªº¤ä´©¡A²¤Æ¤F¨Ï¥Î¤è¦¡¤Î¬yµ{¡A¤]´£°ª¤F AJAX ¦b¦UºØ¤£¦PÂsÄý¾¹ªº¬Û®e©Ê¡C
- DOM¡G©µ¦ù¤F DOM ªºª«¥ó©M¥\¯à¡C
- JSON¡]JavaScript Object Notation¡^¡G¤ä´© JSON ªº¸ê®Æ®æ¦¡¡A¤ñ XML ©ö©óÁA¸Ñ»PŪ¼g¡C
³o¬O¤@Ó¬d¸ßºq¤âªººô¶¡A¥un§A¦b¤å¦rÄæ¦ì¿é¤Jºq¤â¦W¦r¡A´N¥i¥H¨Ï¥Î AJAX ªº«D¦P¨B¶Ç¿é¤è¦¡¡A¥ß§Y¹ï¸ê®Æ®w ajax/test.mdb ¶i¦æ¬d¸ß¡A¨Ã±Nºq¤â¸ê°TÅã¥Ü¦b¤å¦rÄæ¦ì¤U¤è¡C¨Ò¦p¡A·í§ÚÌ¿é¤J¡u¾HÄR§g¡v¨Ã«ö¤U¡u°e¥X¡v®É¡A´N·|¬Ý¨ì¾HÄR§gªº¸ê°T¤w¸gÅã¥Ü¦bºô¶¤U¤è¡G
¦Ó³o¾ãÓ¹Lµ{¨Ã¨S¦³¸g¥Ñºô¶ªº«¸ü¨Ó¹F¦¨¡C¦¹½d¨Òªºì©l½X¦p¤U¡G
°ò¥»¤W¡APrototype.js ¥u¬O±N XMLHttpRequest ¡u¥]°_¨Ó¡v¡A°ò¥»ªº¬yµ{ÁÙ¬O¨S¦³ÅÜ¡A¥H¤W¤@¸`©Ò»¡ªº¤TÓ°ò¥»¨BÆJ¨Ó¬Ý¡A¹ïÀ³Àɮפλ¡©ú¦p¤U¡G
¥t¥~ÁÙ¦³¤@ÂIn¯S§Oª`·N¡G¥Ñ©ó¸ê®Æ®w©Mºô¶½s½Xªº¤£¤@P¡A±`·|¾ÉP¶Ã½Xªº²£¥Í¡A¦]¦¹§Ú̳oÓ½d¨Òªº¨âÓÀɮס]ajaxViaPrototype01.htm ©MqueryDb01.asp¡^¡A³£¬O±Ä¥Î UTF-8 ªº½s½X¡A¦]¦¹ÅªªÌ¦b¶}±Ò³o¨ÇÀɮ׮ɡAnª`·N§Aªº¤å¦r½s¿è¾¹¬O§_¦³¤ä´© UTF-8 ½s½XªºÀÉ®×½s¿è¥\¯à¡C
- ªñºÝªºµo°e¨ç¼Æ¡GsendQuery()
¦¹¨ç¼Æ©w¸q¤F»·ºÝªºµ{¦¡½Xºô¶¡]¦¹¨Ò¬° queryDb01.asp¡^¡A¦P®É¤]¥[¤J¤F°Ñ¼Æ¦C¡]¦¹¨Ò¬° singerName=¾HÄR§g¡^¡A³Ì«á²£¥Í AJAX ª«¥ó¨Ã©w¸q¬ÛÃö°Ñ¼Æ¡A°e¨ì»·ºÝ°õ¦æ¡C¨ä¤¤¦³´XÂInª`·N¡G
- ¡u$F('singerName')¡v¬O Prototype.js ©Ò´£¨ÑªºÂ²¤Æ»yªk¡A¨ä¥\¯à¥þµ¥©ó¡udocument.getElementById('singerName').value¡v¡C¦P¼Ë¦a¡A§Ṳ́]¥i¥H¨Ï¥Î¡u$('singerName')¡v¨Ó¥Nªí id ¬° singerName ªºª«¥ó¡A¨ä¥\¯à¥þµ¥©ó¡udocument.getElementById('singerName')¡v¡C
- ²£¥Í AJAX ª«¥óªº²Ä¤GӰѼƬO¡u{method:'post', parameters:queryString, onComplete:showQueryResult}¡v¡A¦¹°Ñ¼Æ¥þµ¥©ó¤@Ө㦳¤TÓÄæ¦ìªºª«¥ó¡A¦]¦¹§Ú̬Ʀܥi¥H±N sendQuery() ¨ç¼Æªº²Ä¤T¦C±Ôz¡G
var ajax = new Ajax.Request(url, {method:'post', parameters:queryString, onComplete:showQueryResult}); §ï¦¨¤U¦Cµ{¦¡½X¡Gvar ajaxParam = new Object(); ajaxParam.method='post'; ajaxParam.parameters=queryString; ajaxParam.onComplete=showQueryResult; var ajax = new Ajax.Request(url, ajaxParam); ©Ò±o¨ìªºµ²ªG¬O¤@¼Ëªº¡C- »·ºÝªºµ{¦¡½X¡GqueryDb01.asp
¦¹µ{¦¡½X¦p¤U¡G¨ä¥\¯à«Ü²³æ¡A§Y¬O±µ¦¬¨Ï¥ÎªÌ¿é¤Jªººq¤â¦W¦r¡A³y¥X SQL ©R¥O¡A¨Ã°e¤J¸ê®Æ®w¬d¸ß¡A¨Ã±N¬d¸ßµ²ªG¦L¥X¨Ó¡C
- ªñºÝªº±µ¦¬¨ç¼Æ¡GshowQueryResult()
¦b¦¹¨ç¼Æ¤¤¡A§ÚÌ¥u¨Ï¥Î¤@¦Cµ{¦¡½X¡GElement.update('queryResult', xmlHttpObj.responseText); ³o¤]¬O Prototype.js ©Ò´£¨ÑªºÂ²¤Æ»yªk¡A¨ä¥\¯à¥þµ¥©ódocument.getElementById('queryResult').innerHTML=xmlHttpObj.responseText
¨Æ¹ê¤W¡A¤Wzªº½d¨ÒÁÙ¥i¥H§ó²³æ¡A¦pªG§ÚÌ¥u¬O±N¬d¸ßµ²ªGÅã¥Ü¦bºô¶¤W¡A¥i¥H§ï¥Î¥t¤@Ó Prototype.js ¹ï©ó AJAX ©Ò´£¨Ñªº¨ç¼Æ Ajax.Updater()¡A¨Ï¥Î½d¨Ò¦p¤U¡G
¦¹½d¨Ò©M«e¤@Ó½d¨Òªº¥\¯à§¹¥þ¬Û¦P¡A¬Æ¦Ü³s»·ºÝªºµ{¦¡½X³£¬O©ñ¦b queryDb01.asp¡A°ß¤@¤£¦Pªº¬O¡A§Ú̧ï¥Î¤F Ajax.Updater()¡A©Ò¥H¥i¥Hª½±µ«ü©w¦^¶Ç¸ê®Æ©Ò¥²¶·§e²{ªº¦ì¸m¡A½d¨Òì©l½X¦p¤U¡G
¦b¤Wzì©l½X¤¤¡AAjax.Updater() ªº²Ä¤@ӰѼƬO 'queryResult'¡A³o´N¬O¥Nªí¦^¶Ç¸ê®Æ±N·|³Q«ü©w¨ì document.getElementById('queryResult').innerHTML¡A¦]¦¹§ÚÌ´N¤£¥²¥t¥~¦b¼g¤@Ót³dÅã¥Üµ²ªGªº¨ç¼Æ¡A´«¥y¸Ü»¡¡A©M«e¤@Ó½d¨Ò¤ñ¸û¡A§Ṳ́w¸g¤£»Ýn showQueryResult() ³oÓ¨ç¼Æ¤F¡A©Ò¥H¾ãÓºô¶ì©l½X¬Ý°_¨Ó§ó¥[²¼ä¡C
Yn¹ï AJAX ¬yµ{¶i¦æ¶i¤@¨Bªº±±¨î¡A§ÚÌ¥i¥H¨Ï¥Î Ajax.Responders.register ¨Óµù¥U´XÓ¨ç¼Æ¡A¥H«KÅã¥Ü AJAX ªº¤u§@¬yµ{¡C¨Ò¦p¡A¦b¬d¸ß¸ê®Æ®w®É¡AY®É¶¡¹L¤[¡A§Ú̳q±`§Æ±æ¯à°÷¦bºô¶Åã¥Ü¡u¸ê®Æ³B²z¤¤...¡vµ¥¦r¼Ë¡A¥H§KÅý¨Ï¥ÎªÌ¥H¬°¬O»·ºÝ¦øªA¾¹·í¾÷¤F¡C¥H¤U³oÓ²³æªº½d¨Ò¡A´N¯à¹F¨ì¦¹¥\¯à¡G
·í§ÚÌÂIÀ»¡u°e¥X¡v®É¡Aºô¶·|¥ýÅã¥Ü¡u¸ê®Æ³B²z¤¤¡A½Ðµy«á...¡vµ¥¦r¼Ë¡A¦p¤U¡G
µ¥¬d¸ß§¹²¦«á¡A©Ò¦^¶Çªº¸ê®Æ´N·|Åã¥Ü¦bºô¶¤W¡C¦¹½d¨Òªºì©l½X¦p¤U¡G¦b¦¹½d¨Ò¤¤¡A§Ų́ϥΠAjax.Responders.register() ¨Óµù¥U¤F¨âÓ¨ç¼Æ¡A¹ïÀ³¨ì onLoading ¨Æ¥óªº¨ç¼Æ¥i¥H¤£Â_¦L¥X¡u¸ê®Æ³B²z¤¤¡A½Ðµy«á...¡v¤§°T®§¡A¦Ó¹ïÀ³¦Ü onComplete ¨Æ¥óªº¨ç¼Æ«h¥i¥HÅã¥Ü³Ì«á¬d¸ßµ²ªG¡C
JScript µ{¦¡³]p»PÀ³¥Î¡G¥Î©ó¦øªA¾¹ºÝªº ASP Àô¹Ò