AJAX¼´¡°Asynchronous JavaScript and XML¡±£¨·Çͬ²½µÄÓëXML¼¼Êõ£©£¬Ö¸µÄÊÇÒ»Ì××ÛºÏÁ˶àÏî¼¼ÊõµÄä¯ÀÀÆ÷¶ËÍøÒ³¿ª·¢¼¼Êõ¡£AjaxµÄ¸ÅÄîÓɽÜÎ÷¡¤Õ²Ä·Ê¿¡¤¼ÖÈðÌØÌá³ö¡£
1.ѧϰAjaxÒªÇóÕÆÎÕÒÔÏÂ֪ʶ£º
JavaScript¼¼Êõ
ʹÓÃJavaScriptÓëDOM½øÐн»»¥²Ù×÷µÄ¼¼Êõ
»ùÓÚWeb±ê×¼µÄÒ³Ãæ²¼¾Ö
XML¼¼Êõ
JavaScript½âÎöXMLµÄ¼¼Êõ
ÀûÓÃXMLHttpRequest¶ÔÏó·¢³öÒì²½ÇëÇóµÄ¼¼Êõ
·þÎñÆ÷¶Ë±à³Ì¼¼Êõ£¨ÈçJSP»òServlet£©
2.AjaxµÄÓ¦Óãº
AjaxµÄÓ¦ÓÃ
3.»ñÈ¡xmlHttp¶ÔÏ󣨼æÈÝģʽ£©
var xmlHttp; function createXMLHttpRequest(){ if(window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else { xmlHttp = new XMLHttpRequest(); } }4.XMLHttpRequest µÄ·½·¨
·½·¨ ˵Ã÷
abort() Í£Ö¹µ±Ç°ÇëÇó
getAllResponseHeaders() °ÑHTTPÇëÇóµÄËùÓÐÏìÓ¦Êײ¿×÷Ϊ¼ü/Öµ¶Ô·µ»Ø
open("method"£¬"url") ½¨Á¢¶Ô·þÎñÆ÷µÄµ÷ÓÃ
send(content) Ïò·þÎñÆ÷·¢ËÍÇëÇó
setRequestHeader("header"£¬"value") °ÑÖ¸¶¨Êײ¿ÉèÖÃΪËùÌṩµÄÖµ£¬ÉèÖÃÇ°±ØÐëµ÷ÓÃopen£¨£©
5.XMLHttpRequestµÄÊôÐÔ
ÊôÐÔ ËµÃ÷
onreadystatechange ÿ¸ö״̬¸Ä±äʱ¶¼»á´¥·¢Õâ¸öʼþ´¦ÀíÆ÷£¬Í¨³£µ÷ÓÃÒ»¸öJavaScriptº¯Êý
readyState ÇëÇóµÄ״̬£¬1¡¢2¡¢3¡¢4
responseTest ·þÎñÆ÷µÄÏìÓ¦£¬±íʾΪһ¸ö´®
responseXML ·þÎñÆ÷µÄÏìÓ¦£¬±íʾΪXML£¬Õâ¸ö¶ÔÏó¿ÉÒÔ½âÎöΪDOM¶ÔÏó
status ·þÎñÆ÷µÄHTTP״̬Â룬Èç200¡¢404
statusText HTTP״̬ÂëµÄÏàÓ¦Îı¾
¡¡