ʹÓÃAjaxµÄһЩÔÔò
1.Ç°¡¢¶Ëºó¶¼Òª×öºÃ°²È«µÄ°Ñ¹Ø¹¤×÷
ÓÉÓÚAjaxÒ²»á½ÓÊÕºó¶Ë´«ËÍÀ´µÄ×ÊÁÏ£¬¶ÔÕâЩ×ÊÁ϶¼Òª²É²»ÐÅÈÎ̬¶È£¬±ØÐë¼ÓÒÔ¼ì²é¡£
2.¾¡Á¿ÒÔHTTP POST·½·¨´«Êä×ÊÁÏ
ËäÈ»POST²¢·ÇÍòÎÞһʧ£¬µ«±ÈÆðGETÖÁÉÙ½ÏΪ°²È«¡£
3.²»ÒªÖ±½ÓÓÃevalº¯Ê½»½ÆðJSONÎï¼þ
JSONÊDzÉÓÃJavaScriptÎï¼þʵ×ÖµÄ×ÊÁϸñʽ£¬´Óºó¶Ë´«µ½Ajax³Ìʽʱ£¬±ØÐë²ÉÓÃevalº¯Ê½½«Ëü´Ó×Ö´®×ª³ÉÎï¼þ£¬Õâʱ±ØÐëÏÈÐмì²é×ÊÁÏÖÐÊÇ·ñÓзǷ¨×ÖÔª£¬ÒÔÃâ·Ç·¨³Ìʽ½è»úÆôÓá£
4.¹ýÂËijЩʹÓÃÕß¿ÉÓõÄHTMLÓï·¨
Ðí¶àAjaxÍøÕ¾ÔÊÐíʹÓÃÕßÔÚÁôÑÔÖÐʹÓÃHTMLÓï·¨£¬¶øijЩÌض¨Óï·¨Ó¦¸ÃÑϸñÏÞÖÆ£¬ÀýÈ磼plaintext£¾»òÊÇ£¼!- -ÕâÀàÓï·¨£¬¶¼»áÈÃÖÃÓÚÖ®ºóµÄ³ÌʽÂëʧЧ¡£
5.ÈÃʹÓÃÕßÖªµÀ×Ô¼ºµÄ²Ù×÷ÔËÐÐÇé¿ö
µ±AjaxÔØÈë×ÊÁÏÁ¿´óʱ£¬ÓÐʱ»áÈÃʹÓÃÕß²úÉú´í¾õ£¬²»È·¶¨¸Õ¸Õ°´Ïµİ´Å¤ÊÇ·ñ·¢Éú×÷Óá£Òò´Ë¿ª·¢ÈËÔ±±ØÐëÉè¼ÆÊʵ±µÄÌáʾ£¬ÈÃʹÓÃÕßÁ˽âÄ¿Ç°³ÌʽµÄÖ´ÐÐ×´¿ö¡£
6.±£³ÖСÁ¿´«Êä
Èç¹ûÒ»´óÕÅ×ÊÁÏ±í¶¼ÒªÍ¸¹ýDOMµÄ²Ù×÷À´¸Ä±ä£¬²»Èç¾ÍÓɺó¶Ë³ÌʽÓë×ÊÁÏ¿âÀ´²Ù×÷£¬Ð§Òæ¸ü¸ß¡£
7.×¢ÒâÒ×ÓÃÐÔÓëÄÚÈݵÄƽºâ
AjaxËäȻΪʹÓÃÕß´øÀ´ä¯ÀÀʱµÄÒ×ÓÃÐÔ£¬²»¹ýÈç¹û½«ËùÓÐÄÚÈݶ¼Í¸¹ýAjaxÀ´²úÉú£¬»áÔì³ÉËÑÑ°ÒýÇæÎÞ·¨Ë÷Òý×ÊÁϵÄÇé¿ö¡£Òò´ËÓëÄÚÈÝÏà¹ØµÄ²¿·Ö£¬Ðè½÷É÷ʹÓÃAjax¡£
8.Ö´ÐÐÓÅÑŽµ¼¶ÔÔò
±ØÐ뿼Á¿²»Ö§Ô®JavaScriptµÄʹÓÃÕߣ¬Éè·¨ÔÚ²»Ê¹ÓÃÕâЩ¹¦ÄܵÄÇ°ÌáÏ£¬ÈÃËûÃÇ»¹ÄÜÕý³£µØä¯ÀÀÍøÕ¾¡£
Ïà¹ØÎĵµ£º
jQuery µ×²ã AJAX ʵÏÖ¡£¼òµ¥Ò×Óõĸ߲ãʵÏÖ¼û $.get, $.post µÈ¡£$.ajax() ·µ»ØÆä´´½¨µÄ XMLHttpRequest ¶ÔÏó¡£´ó¶àÊýÇé¿öÏÂÄãÎÞÐèÖ±½Ó²Ù×÷¸Ã¶ÔÏ󣬵«ÌØÊâÇé¿öÏ¿ÉÓÃÓÚÊÖ¶¯ÖÕÖ¹ÇëÇó¡£
×¢Ò⣺ Èç¹ûÄãÖ¸¶¨ÁË dataType Ñ¡ÏÇëÈ·±£·þÎñÆ÷·µ»ØÕýÈ·µÄ MIME ÐÅÏ¢£¬(Èç xml ·µ»Ø "text/xml")¡£´íÎóµÄ MIME ÀàÐÍ¿ÉÄܵ¼Ö²»¿ÉÔ¤Ö ......
Ò»¡¢ н¨Ò»¸öAjax_StartµÄÍøÕ¾
¶þ¡¢ ÔÚÍøÕ¾ÖÐÌí¼ÓÒ»¸öweb·þÎñ£¨ws_start.asmx£©
ÔÚvs2008ÖУ¬Ìí¼ÓÒ»¸öweb·þÎñÉú³ÉÁËÁ½¸öÎļþ£¬Ò»¸öÊÇasmxÎļþ£¬Ò»¸öÊÇÔÚApp_codeÀïµÄcsÎļþ£»ÎÒ¾õµÃÕâÑù²¢²»ºÃ£¬Ö ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/ ......
var xmlhttp;
function verify()
{
//2.´´½¨XmlHttpRequest¶ÔÏó
//ÕâÊÇXmlHttpRequest¶ÔÏóÎå²½ÖÐʹÓÃ×ÔÓµÄÒ»²½
//ÐèÒªÕë¶ÔIEºÍÆäËûÀàÐ͵Ää¯ÀÀÆ÷½¨Á¢Õâ¸ö¶ÔÏóµÄ²»Í¬·½Ê½Ð´²»Í¬µÄ´úÂë
if(window.XMLHttpRequest)
{
......
var xmlHttp;
// ´´½¨XMLHttpRequest¶ÔÏó
function createXMLHttpRequest() {
try {
// FireFox, Opera 8.0 +, Safari
xmlHttp = new XMLHttpRequest();
}
catch ......