AjaxÖеķµ»Ø״̬readyStateºÍstatus,ÔÀ´Ã»ÓÐÖØÊÓ¹ýÕâÁ½ÕߵĹØϵ£¬½á¹û½ñÌìд´úÂëʱ³ö²î´íÁË¡£ÎÒµÄÔ´úÂëΪ£º
function requestSome()
{
url=......
xmlHttpRequest.open....
xmlHttpRequest.onreadystatechange = function responseSome();
xmlHttpRequest.send....
}
function responseSome()
{
if(xmlHttpReqeust.readyState == 4)
{
alert(xmlHttpRequest.responseText);
.....
.....
}
}
ÎÒÐèÒªµÃµ½Ò»Ð©ºÏ·¨µÄ·µ»ØÊý¾Ý²¢¶ÔÖ®½øÐд¦Àí£¬µ«·µ»Ø½á¹ûºÜÀëÆ棬ÎÒalert³öµÄ½á¹ûΪ£º<html><head><title>Apache Tomcat/5.5.26 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif ......
$.ajax({
type: "POST", //·ÃÎÊWebServiceʹÓÃPost·½Ê½ÇëÇó
contentType: "application/json",
url: "UpdateNews.aspx/InsertLocalImages",
data: "{dirName:'" + UploadPath + "',ImagePath:'" + imgpath + "',ImageName:'" + imgname + "',filetitle:'" + title + "',filedate:'" + date + "',fileexp:'" + exp + "',filekeyw:'" + keyw + "',iscovr:'" + iscovr + "'}",
dataType: 'json',
succ ......
$.ajax({
type: "POST", //·ÃÎÊWebServiceʹÓÃPost·½Ê½ÇëÇó
contentType: "application/json",
url: "UpdateNews.aspx/InsertLocalImages",
data: "{dirName:'" + UploadPath + "',ImagePath:'" + imgpath + "',ImageName:'" + imgname + "',filetitle:'" + title + "',filedate:'" + date + "',fileexp:'" + exp + "',filekeyw:'" + keyw + "',iscovr:'" + iscovr + "'}",
dataType: 'json',
succ ......
//³õʼ»¯¶ÔÏó²¢·¢³öXMLHttpRequestÇëÇó
xmlHttp= false;
if (window.XMLHttpRequest)
{ //MozillaµÈÆäËûä¯ÀÀÆ÷
xmlHttp= new XMLHttpRequest();
if (xmlHttp.overrideMimeType)
{
xmlHttp.overrideMimeType("text/xml"); /*Èç¹ûÀ´×Ô·þÎñÆ÷µÄÏìӦûÓÐ XML mime-type Í·²¿(header)£¬ÔòһЩ°æ±¾µÄ Mozillaä¯ÀÀÆ÷²»ÄÜÕý³£ÔËÐС£¶ÔÓÚÕâÖÖÇé¿ö£¬httpRequest.overrideMimeType('text/xml'); Óï¾ä½«¸²¸Ç·¢Ë͸ø·þÎñÆ÷µÄÍ·²¿£¬Ç¿ÖÆ text/xml ×÷Ϊ mime-type¡£*/
}
}
else if (window.ActiveXObject)
{ //IEä¯ÀÀÆ÷
try
{ //Microsoft ä¯ÀÀÆ÷ Internet Explorer ʹÓà MSXML ½âÎöÆ÷´¦Àí XML
xmlHttp= new ActiveXObject("Msxml2.XMLHTTP"); //³¢ÊÔʹÓÃÒ»¸ö°æ±¾µÄ MSXML ´´½¨¶ÔÏó£¬Èç¹ûʧ°ÜÔòʹÓÃÁíÒ»¸ö°æ±¾´´½¨¸Ã¶ÔÏó¡£
}
catch (e)
{
& ......
jQueryȷʵÊÇÒ»¸öͦºÃµÄÇáÁ¿¼¶µÄJS¿ò¼Ü£¬ÄÜ°ïÖúÎÒÃÇ¿ìËٵĿª·¢JSÓ¦Ó㬲¢ÔÚÒ»¶¨³Ì¶ÈÉϸıäÁËÎÒÃÇдJavaScript´úÂëµÄÏ°¹ß¡£
·Ï»°ÉÙ˵£¬Ö±½Ó½øÈëÕýÌ⣬ÎÒÃÇÏÈÀ´¿´Ò»Ð©¼òµ¥µÄ·½·¨£¬ÕâЩ·½·¨¶¼ÊǶÔjQuery.ajax()½øÐзâ×°ÒÔ·½±ãÎÒÃÇʹÓõķ½·¨£¬µ±È»£¬Èç¹ûÒª´¦Àí¸´ÔÓµÄÂß¼£¬»¹ÊÇÐèÒªÓõ½jQuery.ajax()µÄ(Õâ¸öºóÃæ»á˵µ½).
1. load( url, [data], [callback] ) £ºÔØÈëÔ¶³Ì HTML Îļþ´úÂë²¢²åÈëÖÁ DOM ÖС£
url (String) : ÇëÇóµÄHTMLÒ³µÄURLµØÖ·¡£
data (Map) : (¿ÉÑ¡²ÎÊý) ·¢ËÍÖÁ·þÎñÆ÷µÄ key/value Êý¾Ý¡£
callback (Callback) : (¿ÉÑ¡²ÎÊý) ÇëÇóÍê³Éʱ(²»ÐèÒªÊÇsuccessµÄ)µÄ»Øµ÷º¯Êý¡£
Õâ¸ö·½·¨Ä¬ÈÏʹÓà GET ·½Ê½À´´«µÝµÄ£¬Èç¹û[data]²ÎÊýÓд«µÝÊý¾Ý½øÈ¥£¬¾Í»á×Ô¶¯×ª»»ÎªPOST·½Ê½µÄ¡£jQuery 1.2 ÖУ¬¿ÉÒÔÖ¸¶¨Ñ¡Ôñ·û£¬À´É¸Ñ¡ÔØÈëµÄ HTML Îĵµ£¬DOM Öн«½ö²åÈëɸѡ³öµÄ HTML ´úÂë¡£Óï·¨ÐÎÈç "url #some > selector"¡£
Õâ¸ö·½·¨¿ÉÒԺܷ½±ãµÄ¶¯Ì¬¼ÓÔØһЩHTMLÎļþ£¬ÀýÈç±íµ¥¡£
ʾÀý´úÂ룺
$(".ajax.load").load("http://www.cnblogs.com/QLeelulu/archive/2008/03/30/1130270.html .post",
function (responseText, textStatus, XMLHttpRequest){
this;//ÔÚÕâÀ ......
XMLHttpRequestÊÇAjax¼¼ÊõÌåϵÖÐ×îΪºËÐĵļ¼Êõ¡£È±ÉÙÁËËü£¬AjaxµÄÆäÓ༼Êõ¾ÍÎÞ·¨³ÉΪһ¸öÓлúµÄÕûÌ壬½«»áÍÁ±ÀÍ߽⡣
¡¡¡¡1999ÄêÉÏ°ëÄ꣬MSÔÚIE 5.0°æÖÐÊ×´ÎÖ§³ÖÕâÖÖ¼¼Êõ£¬ËûÃÇÊÇͨ¹ýÒ»¸öÃûΪXMLHTTPµÄActiveX¶ÔÏóÀ´Ö§³ÖÕâÖÖ¼¼ÊõµÄ¡£XMLHTTP¶ÔÏóʹµÃÒ³ÃæÖеĽű¾¾ßÓÐÁËÔÚ²»Ë¢ÐÂÒ³ÃæµÄÇé¿öÏÂÖ±½ÓÓë·þÎñÆ÷ͨÐŵÄÄÜÁ¦¡£ÔÚ´Ë֮ǰ£¬Äܹ»×öµ½Õâ¼þʵÄΨһ¼¼ÊõÊÇͨ¹ýIFrame£¬È»¶øÕⳬԽÁËIFrame×î³õÉè¼ÆµÄÄ¿±ê£¬ÊÇÒ»ÖÖ´æÔÚDZÔÚΣÏÕµÄhack×ö·¨¡£¼ÈÈ»ÒѾÓкܶ಻Êعæ¾ØµÄ¿ª·¢Õß×ö³öÁËÔ½¹ìµÄÐÐΪ£¬²¢ÇÒÊÂʵ֤Ã÷ÕâÑùµÄ¿ª·¢·½Ê½È·Êµ·Ç³£ÓмÛÖµ£¬Ò²²»»á¶Ôϵͳ°²È«Ôì³ÉʲôÆÆ»µ¡£ÓÚÊÇMS¾Í´ÓÉÆÈçÁ÷µØ·¢Ã÷ÁËXMLHTTP¶ÔÏó£¬×¨ÃÅÓÃÀ´Îªä¯ÀÀÆ÷ÖеĽű¾£¨ÔÚIEÖоÍÊÇJScriptºÍVBScript£©ÌṩÕâÑùµÄ·þÎñÆ÷ͨÐÅÄÜÁ¦¡£
¡¡¡¡XMLHTTP¶ÔÏó´óÊÜ»¶Ó£¬µ½ÁË2000ÄêËü¼¸ºõÒѾ³ÉΪÁËÊÂʵÉϵıê×¼¡£MozillaÔÚÕâÒ»ÄêʵÏÖÁ˾ßÓÐÏàͬ½Ó¿ÚµÄÔÉú¶ÔÏ󣬳Æ×÷XMLHttpRequest¶ÔÏ󡣺óÀ´Opera¡¢SafariµÈä¯ÀÀÆ÷Ò²¶¼Ïà¼ÌʵÏÖÁËXMLHttpRequest¶ÔÏó¡£ÏÖÔÚXMLHttpRequestÊÇÕâ¸ö¼¼ÊõµÄÕýʽÃû³Æ¡£
¡¡¡¡AjaxËùÒÀÀµµÄ¼¼ÊõÖ®ÖÐΨһһ¸öÉÐδÕýʽ±ê×¼»¯µÄ²¿·Ö¾ÍÊÇXMLHttpRequest£¬²»¹ýÏÖÔÚW3CÒѾ½«ÆäÁÐÈëÁ˹¤×÷²Ý°¸£¬Ó¦¸ÃºÜ¿ì¾Í» ......
1£¬±¾Àý×ÓʵÏÖÒ»¸öAjax¸ü¸ÄÊý¾ÝµÄÀý×Ó
Èçͼ£º
1£¬Ð½¨xmlÎļþ£»ÆäÄÚÈÝÈçÏ£º
<?xml version="1.0" encoding="utf-8"?>
<userinfo>
<user>
<id>I</id>
<name>wtq</name>
<password>123456</password>
<phone>0595-85538649</phone>
<city>ȪÖÝ</city>
</user>
<user>
<id>1</id>
<name>1</name>
<password>1</password>
<phone>1</phone>
<city>1</city>
</user>
<user>
<id>1</id>
<name>1</name>
<password>1</password>
<phone>1</phone>
<city>1</city>
</user>
<user>
<id>123</id>
<name>ÍõÌìÇÉ</name>
<password>123</password>
<phone>13616009873</phone>
<city>jinjiang</city>
</user>
< ......