「AJAX 上手篇」修訂間的差異
出自 MozTW Wiki
RicvaReldr(對話 | 貢獻) (http://huruple.qsh.eu/20090102-movie-coloring.htm) |
RicvaReldr(對話 | 貢獻) 小 (http://saererg.0lx.net/20081110-rock-hudson-jane.htm) |
||
行 1: | 行 1: | ||
+ | [http://saererg.0lx.net/20081110-rock-hudson-jane.htm rock hudson jane wyman movie] [http://zelzelqa.is-the-boss.com/news-queensland-learners-2008-12-25.html queensland learners licence test] [http://fademon.0lx.net/article-711.htm karas xxx free video] [http://roladarh.strefa.pl/news-1464.html record flash movies] [http://lofaako.strefa.pl/article350.html new movie releases to video] | ||
[http://huruple.qsh.eu/20090102-movie-coloring.htm movie coloring pages] [http://tarobasal.strefa.pl/article1479.htm james newman videogames] [http://bukgetert.0lx.net/article-425.htm jeux video.com] [http://vihencbr.0lx.net/panasonic-3ccd.html panasonic 3ccd video cameras] [http://naceceli.qsh.eu/page1153.html susan selles movie] | [http://huruple.qsh.eu/20090102-movie-coloring.htm movie coloring pages] [http://tarobasal.strefa.pl/article1479.htm james newman videogames] [http://bukgetert.0lx.net/article-425.htm jeux video.com] [http://vihencbr.0lx.net/panasonic-3ccd.html panasonic 3ccd video cameras] [http://naceceli.qsh.eu/page1153.html susan selles movie] | ||
[http://releltl.0lx.net/20081112-aguilera-photo.html aguilera photo shoot video] [http://naceceli.qsh.eu/page1188.html extreme ops movie cast] [http://tulilre.strefa.pl/2008-12-24-second-x-file-movie.html second x file movie] [http://tacataca.strefa.pl/comment-1768.htm indianmoviesonline] [http://betheres.qsh.eu/comment-710.htm prodigy breathe music video] | [http://releltl.0lx.net/20081112-aguilera-photo.html aguilera photo shoot video] [http://naceceli.qsh.eu/page1188.html extreme ops movie cast] [http://tulilre.strefa.pl/2008-12-24-second-x-file-movie.html second x file movie] [http://tacataca.strefa.pl/comment-1768.htm indianmoviesonline] [http://betheres.qsh.eu/comment-710.htm prodigy breathe music video] | ||
− | {{MDC|AJAX: | + | {{MDC|AJAX:äøÃÂæÃÂÃÂçïÃÂ}} |
− | + | éÃÂÃÂçïÃÂæÃÂÃÂçëàèêêæÃÂàAJAX çÃÂøéÃÂÃÂæÃÂÃÂèáÃÂçÃÂÃÂÃÂ¥ÃÂúçäÃÂïüÃÂäøææÃÂÃÂäþÃÂÃ¥ïæäþÃÂäþÃÂæÃÂèäøÃÂæÃÂÃÂãÃÂà| |
− | == | + | == çììäøÃÂæÃÂÃÂ¥ âÃÂàèêêèÃÂòãÃÂÃÂèëÃÂãÃÂàïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂ'''æÃÂÃÂéúüçÃÂüÃÂ¥ÃÂú XMLHttpRequest'''ãÃÂÃÂïüà== |
− | + | çÃÂúäúÃÂçÃÂè JavaScript Ã¥ðÃÂäüúæÃÂÃÂÃÂ¥ÃÂèçÃÂüéÃÂàHTTP èæÃÂæñÃÂïüÃÂÃ¥ÿÃÂ
éàÃÂÃÂ¥ÃÂ
ÃÂäûÃ¥çÃÂøéÃÂÃÂçÃÂÃÂéáÃÂÃÂ¥ÃÂÃ¥ïüÃÂclassïüÃÂèãýÃÂ¥ÃÂúÃ¥ïæéëÃÂïüÃÂinstanceïüÃÂãÃÂÃÂInternet Explorer éæÃÂÃÂ¥ÃÂ
ÃÂäûÃÂ¥ ActiveX çÃÂéäûöæÃÂùÃ¥üÃÂæÃÂÃÂäþà<code>XMLHTTP</code> éáÃÂÃÂ¥ÃÂÃ¥ïüÃÂèÃÂàMozillaãÃÂÃÂSafari ÃÂ¥ÃÂÃÂÃÂ¥ÃÂ
öäûÃÂçÃÂÃÂèæýÃÂ¥ÃÂèÃÂ¥ÃÂÃÂéÃÂèÃ¥þÃÂäûÃÂ¥ <code>XMLHttpRequest</code> éáÃÂÃÂ¥ÃÂÃ¥æÃÂïæÃÂôæÃÂä ActiveX çÃÂéäûöäøÃÂçÃÂÃÂéáÃÂÃÂ¥ÃÂÃÂ¥ÃÂ¥ÃÂÃÂÃ¥ñìæÃÂçãÃÂà| |
− | + | ÃÂ¥ÃÂàæÃÂäïüÃÂÃ¥æÃÂæÃÂÃÂæÃÂóè÷èçÃÂÃÂèæýÃÂ¥ÃÂèïüÃÂéÃÂãéúüÃÂ¥ÃÂïäûÃ¥éÃÂÃÂéúüÃ¥ïëïüà| |
<pre> | <pre> | ||
行 19: | 行 20: | ||
</pre> | </pre> | ||
− | ( | + | (çÃÂñæÃÂüéÃÂÃÂæîõçèÃÂÃ¥üÃÂÃÂ¥ÃÂÃÂ
äþÃÂèêêæÃÂÃÂïüÃÂæÃÂÃÂäûÃ¥æÃÂïæÃÂáæÃÂÃÂçðáæÃÂùÃ¥üÃÂÃ¥ïëÃÂ¥ÃÂúãÃÂÃÂæÃÂìæÃÂÃÂçììäøÃÂæÃÂÃ¥äøÃÂæÃÂÃÂÃÂ¥ÃÂæäøÃÂçèîæÃÂÃÂÃÂ¥ÃÂÃÂæïÃÂèüÃÂÃ¥øøçÃÂèçÃÂÃÂÃ¥ïëæóÃÂãÃÂÃÂ) |
− | + | æÃÂÃÂäúÃÂçÃÂÃÂæÃÂìçÃÂàMozilla çÃÂÃÂèæýÃÂ¥ÃÂèÃÂ¥ÃÂèäüúæÃÂÃÂÃÂ¥ÃÂèéÃÂÃÂÃÂ¥ÃÂÃÂçÃÂÃÂèóÃÂæÃÂÃÂæÃÂêÃÂ¥ÃÂë XML mime-type æêÃÂéàÃÂïüÃÂheaderïüÃÂæÃÂÃÂæÃÂÃÂÃÂ¥ÃÂúéÃÂïãÃÂÃÂçÃÂúäúÃÂéÃÂÿÃÂ¥ÃÂ
ÃÂéÃÂÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂéáÃÂïüÃÂäýàÃÂ¥ÃÂïäûÃ¥çÃÂèäøÃÂÃÂ¥ÃÂÃÂæÃÂùæóÃÂèæÃÂÃ¥ïëäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂæêÃÂéàÃÂïüÃÂäûÃÂ¥ÃÂ¥ÃÂ
ÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂäøÃÂæÃÂï <code>text/xml</code>ãÃÂà| |
<pre> | <pre> | ||
行 28: | 行 29: | ||
</pre> | </pre> | ||
− | + | æÃÂÃ¥äøÃÂäþÃÂæÃÂïèæÃÂæñúÃ¥îÃÂäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂèóÃÂæÃÂÃÂÃ¥þÃÂçÃÂÃÂèÃÂÃÂçÃÂÃÂæÃÂùÃ¥üÃÂïüÃÂæÃÂäæÃÂÃÂäýàÃÂ¥ÃÂêèæÃÂäûÃÂ¥ <code>onreadystatechange</code> éÃÂÃÂÃÂ¥ÃÂÃÂÃ¥ñìæÃÂçæÃÂÃÂæÃÂÃÂèæÃÂèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüçÃÂàJavaScript ÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñÃÂ¥ÃÂóÃÂ¥ÃÂïïüÃÂäþÃÂÃ¥æÃÂïüà| |
<code>http_request.onreadystatechange = nameOfTheFunction;</code> | <code>http_request.onreadystatechange = nameOfTheFunction;</code> | ||
− | + | æóèæÃÂÃÂïüÃÂæÃÂÃÂÃ¥îÃÂçÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñÃ¥þÃÂäøÃÂÃÂ¥ÃÂàæÃÂìèÃÂÃÂäùÃÂæòÃÂæÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøãÃÂÃÂéÃÂääúÃÂæÃÂÃÂÃ¥îÃÂÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñÃ¥äÃÂïüÃÂäýàäùÃÂèÃÂýçÃÂè Javascript ÃÂ¥ÃÂóæÃÂÃÂÃ¥îÃÂçþéÃÂ¥ÃÂýÃ¥üÃÂçÃÂÃÂæÃÂùæóÃÂäþÃÂÃ¥îÃÂäøÃÂÃÂ¥ÃÂÃÂæÃÂðçÃÂÃÂèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂïüÃÂÃ¥æÃÂäøÃÂïüà| |
<pre> | <pre> | ||
http_request.onreadystatechange = function(){ | http_request.onreadystatechange = function(){ | ||
− | // | + | // ÃÂ¥ÃÂÃÂäúÃÂäúà|
}; | }; | ||
</pre> | </pre> | ||
− | + | æñúÃ¥îÃÂèÃÂÃÂçÃÂÃÂæÃÂùÃ¥üÃÂäùÃÂÃ¥þÃÂäýàÃ¥þÃÂçâúÃ¥ïæçÃÂüÃÂ¥ÃÂú requestïüÃÂæÃÂäæÃÂÃÂéÃÂÃÂÃÂ¥ÃÂëçÃÂè HTTP request éáÃÂÃÂ¥ÃÂÃ¥çÃÂà<code>open()</code> ÃÂ¥ÃÂà<code>send()</code> æÃÂùæóÃÂïüÃÂÃ¥æÃÂäøÃÂïüà| |
<pre> | <pre> | ||
行 47: | 行 48: | ||
</pre> | </pre> | ||
− | * <code>open()</code> | + | * <code>open()</code> çÃÂÃÂçììäøÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøæÃÂï HTTP request çÃÂÃÂæÃÂùæóÃÂïüÃÂäùÃÂÃ¥ðñæÃÂïÃ¥þàGETãÃÂÃÂPOSTãÃÂÃÂHEAD äøÃÂæÃÂÃÂäøÃÂäýÿçÃÂèïüÃÂäúæÃÂ¥ÃÂïçÃÂèäýàäøûæéÃÂäøÃÂæÃÂïæÃÂôçÃÂÃÂæÃÂùÃ¥üÃÂãÃÂÃÂçÃÂúéÃÂõÃ¥þê HTTP æèÃÂæúÃÂïüÃÂèëÃÂèèÃÂÃ¥þÃÂéÃÂÃÂäúÃÂæÃÂùæóÃÂéÃÂýæÃÂïÃ¥äçÃ¥ïëïüÃÂäøÃÂçÃÂöæÃÂÃÂçÃÂÃÂçÃÂÃÂèæýÃÂ¥ÃÂèïüÃÂÃ¥æàFirefoxïüÃÂæÃÂÃÂèèñäøÃÂæÃÂÃÂçÃÂÃÂäýàãÃÂÃÂÃÂ¥ÃÂ
öäûàHTTP request ÃÂ¥ÃÂïäûÃ¥æÃÂïæÃÂôçÃÂÃÂæÃÂùæóÃÂÃÂ¥ÃÂÃÂèáèèëÃÂÃÂ¥ÃÂÃÂèÃÂà[http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html W3C èæÃÂæàüæÃÂø]ãÃÂà|
− | * | + | * çììäúÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøæÃÂïçÃÂîæèàURLãÃÂÃÂÃÂ¥ÃÂúæÃÂüÃ¥îÃÂÃÂ¥ÃÂ
èèÃÂÃÂéÃÂÃÂïüÃÂäýàäøÃÂèÃÂýÃÂ¥ÃÂëçÃÂèÃÂ¥ÃÂÃÂçöòÃÂ¥ÃÂÃÂäûÃ¥åäÃÂçÃÂÃÂçöòéàÃÂãÃÂÃÂÃ¥æÃÂæÃÂÃÂçöòÃÂ¥ÃÂÃÂäøÃÂÃÂ¥ÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂëçÃÂè <code>open()</code> æÃÂÃÂæÃÂÃÂÃÂ¥ÃÂúçÃÂþãÃÂÃÂæìÃÂéÃÂÃÂäøÃÂèöóïüÃÂæÃÂÃÂçõÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂãÃÂÃÂéÃÂãéáÃÂçÃÂÃÂéÃÂïèêäãÃÂÃÂéÃÂÃÂÃ¥øøÃ¥äçÃ¥äÃ¥æÃÂÃÂçÃÂïçÃÂÃÂéÃÂïèêäÃ¥äÃÂçÃÂúÃÂ¥ÃÂè domain.tld çöòçÃÂÃÂçöòçëÃÂäøÃÂÃÂ¥ÃÂüÃÂ¥ÃÂë www.domain.tld äøÃÂçÃÂÃÂçöòéàÃÂïüÃÂÃÂ¥ÃÂÃÂ
æÃÂïäøÃÂéûÃÂéûÃÂÃ¥÷îÃÂ¥ÃÂÃ¥éÃÂýäøÃÂèáÃÂãÃÂà|
− | * | + | * çììäøÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøæñúÃ¥îÃÂæÃÂä request æÃÂïÃÂ¥ÃÂæäøÃÂÃÂ¥ÃÂÃÂæÃÂÃ¥éÃÂòèáÃÂïüÃÂÃ¥æÃÂæÃÂÃÂèèÃÂÃ¥îÃÂçÃÂú <code>TRUE</code> ÃÂ¥ÃÂÃÂÃÂ¥ÃÂóäýÿäüúæÃÂÃÂÃÂ¥ÃÂèÃ¥ðÃÂæÃÂêÃÂ¥ÃÂóÃÂ¥ÃÂÃÂèóÃÂæÃÂÃÂäùÃÂæÃÂÃÂçùüçúÃÂÃÂ¥ÃÂ÷èáÃÂÃÂ¥ÃÂ
öéäÃÂçÃÂÃÂçèÃÂÃ¥üÃÂïüÃÂéÃÂÃÂäùÃÂÃ¥ðñæÃÂï AJAX äøÃÂçììäøÃÂÃÂ¥ÃÂàA äûãèáèçÃÂÃÂæÃÂÃÂçþéãÃÂà|
− | <code>send()</code> | + | <code>send()</code> çÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøÃÂ¥ÃÂèäûÃÂ¥ POST çÃÂüÃÂ¥ÃÂú request æÃÂÃÂÃÂ¥ÃÂïäûÃ¥æÃÂïäûûäýÃÂæÃÂóÃÂ¥ÃÂóçõæäüúæÃÂÃÂÃÂ¥ÃÂèçÃÂÃÂæÃÂñèÃ¥ÿïüÃÂèÃÂÃÂèóÃÂæÃÂÃÂÃÂ¥ÃÂÃÂäûÃ¥æÃÂÃ¥èéâÃÂ¥ÃÂÃÂäøòçÃÂÃÂæÃÂùÃ¥üÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂúïüÃÂäþÃÂÃ¥æÃÂïüà|
<code>name=value&anothername=othervalue&so=on</code> | <code>name=value&anothername=othervalue&so=on</code> | ||
− | + | äøÃÂéÃÂÃÂÃ¥æÃÂæÃÂÃÂäýàæÃÂóèæÃÂäûÃÂ¥ POST æÃÂùÃ¥üÃÂÃÂ¥ÃÂóéÃÂÃÂèóÃÂæÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂÃ¥ÿÃÂ
éàÃÂÃÂ¥ÃÂ
ÃÂÃ¥ðàMIME ÃÂ¥ÃÂÃÂæÃÂ
ÃÂæÃÂùÃ¥åýïüÃÂÃ¥æÃÂäøÃÂïüà| |
<pre> | <pre> | ||
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | ||
</pre> | </pre> | ||
− | + | ÃÂ¥ÃÂæÃÂ¥ÃÂÃÂäüúæÃÂÃÂÃÂ¥ÃÂèÃ¥ðñäøÃÂæÃÂÃÂçÃÂÃÂäýàÃÂ¥ÃÂóéÃÂÃÂäþÃÂçÃÂÃÂèóÃÂæÃÂÃÂäúÃÂãÃÂà| |
− | == | + | == çììäúÃÂæÃÂÃÂ¥ âÃÂàãÃÂÃÂÃ¥ðñäøÃÂÃÂ¥ÃÂéïüÃÂãÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂèÃÂÃÂçÃÂÃÂäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂèóÃÂæÃÂÃÂãÃÂÃÂïüà== |
− | + | ÃÂ¥ÃÂóÃÂ¥ÃÂú request æÃÂÃÂÃ¥ÿÃÂ
éàÃÂæÃÂÃÂäþÃÂèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüçÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñãÃÂà| |
<code>http_request.onreadystatechange = nameOfTheFunction;</code> | <code>http_request.onreadystatechange = nameOfTheFunction;</code> | ||
− | + | éÃÂãéúüäþÃÂçÃÂÃÂçÃÂÃÂéÃÂÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂèéòÃÂ¥ÃÂÃÂäúÃÂäûÃÂéúüãÃÂÃÂéæÃÂÃÂ¥ÃÂ
ÃÂïüÃÂÃ¥îÃÂÃ¥ÿÃÂ
éàÃÂæêâæÃÂÃÂ¥ request çÃÂîÃÂ¥ÃÂÃÂçÃÂÃÂçÃÂÃÂæÃÂ
ÃÂïüÃÂÃ¥æÃÂæÃÂÃÂçÃÂÃÂæÃÂ
ÃÂÃÂ¥ÃÂüçÃÂú 4 äûãèáèäüúæÃÂÃÂÃÂ¥ÃÂèÃ¥÷òçöÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂæÃÂÃÂæÃÂÃÂèóÃÂèèÃÂäúÃÂïüÃÂäþÿÃÂ¥ÃÂïäûÃ¥éÃÂÃÂÃ¥çÃÂèçãæÃÂÃÂæÃÂÃÂÃ¥þÃÂèóÃÂèèÃÂãÃÂà| |
<pre> | <pre> | ||
if (http_request.readyState == 4) { | if (http_request.readyState == 4) { | ||
− | // | + | // äøÃÂÃÂ¥ÃÂàok, çùüçúÃÂèçãæÃÂà|
} else { | } else { | ||
− | // | + | // éÃÂÃÂæòÃÂÃ¥îÃÂæÃÂà|
} | } | ||
</pre> | </pre> | ||
− | <code>readyState</code> | + | <code>readyState</code> æÃÂÃÂæÃÂÃÂÃÂ¥ÃÂïèÃÂýçÃÂÃÂÃÂ¥ÃÂüÃ¥æÃÂäøÃÂïüà|
− | * 0 ( | + | * 0 (éÃÂÃÂæòÃÂéÃÂÃÂÃ¥çÃÂ) |
− | * 1 ( | + | * 1 (èîÃÂÃÂ¥ÃÂÃÂäøÃÂ) |
− | * 2 ( | + | * 2 (Ã¥÷òèîÃÂÃÂ¥ÃÂÃÂ) |
− | * 3 ( | + | * 3 (èóÃÂèèÃÂäúäæÃÂÃÂäøÃÂ) |
− | * 4 ( | + | * 4 (äøÃÂÃÂ¥ÃÂÃÂÃ¥îÃÂæÃÂÃÂ) |
− | ([http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/readystate_1.asp | + | ([http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/readystate_1.asp èóÃÂæÃÂÃÂäþÃÂæúÃÂ: MSDN]) |
− | + | æÃÂÃ¥äøÃÂäþÃÂèæÃÂæêâæÃÂÃ¥äüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂàHTTP çÃÂÃÂæÃÂ
ÃÂçâüãÃÂÃÂæÃÂÃÂæÃÂÃÂçÃÂÃÂæÃÂ
ÃÂçâüÃÂ¥ÃÂÃÂèáèÃÂ¥ÃÂïæÃÂü [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html W3C çöòçëÃÂ]äøÃÂæÃÂÃÂ¥ÃÂ¥ÃÂðïüÃÂäýÃÂæÃÂÃÂÃÂ¥ÃÂÃÂèæÃÂçîáçÃÂÃÂæÃÂï <code>200 OK</code> éÃÂÃÂçèîçÃÂÃÂæÃÂ
ÃÂãÃÂà| |
<pre> | <pre> | ||
if (http_request.status == 200) { | if (http_request.status == 200) { | ||
− | // | + | // èÃÂìäúÃÂÃÂ¥ÃÂ
÷ÃÂ¥ÃÂà|
} else { | } else { | ||
− | // | + | // äüüäùÃÂæÃÂÃÂéûÃÂÃÂ¥ÃÂÃÂéáÃÂïüÃÂæÃÂÃÂèèñäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂäúà404 (æÃÂÃ¥çÃÂáæÃÂäéàÃÂ) æÃÂÃÂèÃÂÃÂ
500 (ÃÂ¥ÃÂ
çéÃÂèéÃÂïèêä) äûÃÂéúüçÃÂà|
} | } | ||
</pre> | </pre> | ||
− | + | æêâæÃÂÃÂ¥ÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂàHTTP çÃÂÃÂæÃÂ
ÃÂçâüÃ¥þÃÂïüÃÂèæÃÂæÃÂÃÂéúüèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂèóÃÂæÃÂÃÂÃ¥ðñçÃÂñäýàæñúÃ¥îÃÂäúÃÂãÃÂÃÂæÃÂÃÂÃÂ¥ÃÂ
éçèîÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂèóÃÂæÃÂÃÂçÃÂÃÂæÃÂùÃ¥üÃÂïüà| |
− | * <code>http_request.responseText</code> | + | * <code>http_request.responseText</code> âÃÂàéÃÂÃÂæèãæÃÂÃÂæÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüçÃÂöÃÂ¥ÃÂÃÂäøòçÃÂè |
− | * <code>http_request.responseXML</code> | + | * <code>http_request.responseXML</code> âÃÂàéÃÂÃÂæèãæÃÂÃÂæÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüèæÃÂçÃÂú <code>XMLDocument</code> çÃÂéäûöïüÃÂèÃÂÃÂÃ¥þÃÂÃÂ¥ÃÂïçÃÂè JavaScript DOM çÃÂøéÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂèÃÂÃÂçÃÂà|
− | == | + | == çììäøÃÂæÃÂÃÂ¥ - èÃÂìäúÃÂäÿñÃÂ¥ÃÂà- çðáÃÂ¥ÃÂîçïÃÂäþà== |
− | + | Ã¥åýïüÃÂæÃÂÃ¥èÃÂÃÂÃ¥ðñÃÂ¥ÃÂÃÂäøÃÂæìáçðáÃÂ¥ÃÂîçÃÂàHTTP çïÃÂäþÃÂïüÃÂæüÃÂçäúæÃÂùæÃÂÃÂçÃÂÃÂÃÂ¥ÃÂÃÂéàÃÂ
æÃÂÃÂÃ¥÷çãÃÂÃÂéÃÂÃÂæîõ JavaScript æÃÂÃÂÃÂ¥ÃÂÃÂäüúæÃÂÃÂÃÂ¥ÃÂèèæÃÂäøÃÂäûýèãáéàÃÂæÃÂÃÂãÃÂÃÂI'm a test.ãÃÂÃÂÃÂ¥ÃÂÃÂæèãçÃÂàHTML æÃÂÃÂäûö(<code>test.html</code>)ïüÃÂèÃÂÃÂÃ¥þÃÂäûÃÂ¥ <code>alert()</code> Ã¥ðÃÂæÃÂÃÂäûöÃÂ¥ÃÂ
çÃ¥îùÃÂ¥ÃÂÃÂÃÂ¥ÃÂúãÃÂà| |
<pre> | <pre> | ||
行 156: | 行 157: | ||
</pre> | </pre> | ||
− | + | ÃÂ¥ÃÂèæÃÂäçïÃÂäþÃÂäøÃÂïüà| |
− | * | + | * éæÃÂÃÂ¥ÃÂ
ÃÂäýÿçÃÂèèÃÂÃÂ
æÃÂÃÂäøÃÂãÃÂÃÂMake a requestãÃÂà|
− | * | + | * éÃÂÃÂéúüäøÃÂäþÃÂÃ¥ðñæÃÂÃÂÃÂ¥ÃÂüÃÂ¥ÃÂë <code>makeRequest()</code> ÃÂ¥ÃÂýÃ¥üÃÂïüÃÂäúæÃÂ¥ÃÂóÃÂ¥ÃÂ
ÃÂ¥ÃÂ¥ÃÂÃÂæÃÂøÃÂ¥ÃÂü <code>test.html</code> (äùÃÂÃ¥ðñæÃÂïéÃÂãäûý HTML æêÃÂçÃÂÃÂÃÂ¥ÃÂÃÂçèñïüÃÂæÃÂþÃÂ¥ÃÂèÃÂ¥ÃÂÃÂçÃÂîéÃÂÃÂäøÃÂ) |
− | * | + | * æÃÂÃ¥èÃÂÃÂçÃÂüÃÂ¥ÃÂú requestïüÃÂèÃÂÃÂÃ¥þÃÂæÃÂÃÂÃ¥ðÃÂäøûÃ¥ðÃÂæìÃÂäúäçõæ <code>onreadystatechange</code> æÃÂÃÂÃ¥îÃÂçÃÂà<code>alertContents()</code> ÃÂ¥ÃÂýÃ¥üà|
− | * <code>alertContents()</code> | + | * <code>alertContents()</code> æêâæÃÂÃÂ¥ÃÂ¥ÃÂÃÂæÃÂÃÂæÃÂïÃÂ¥ÃÂææÃÂãÃ¥øøïüÃÂèÃÂÃÂÃ¥þÃÂäûÃÂ¥ <code>alert()</code> Ã¥ðà<code>test.html</code> çÃÂÃÂÃÂ¥ÃÂ
çÃ¥îùÃÂ¥ÃÂÃÂÃÂ¥ÃÂú |
− | + | äýàÃÂ¥ÃÂïäûÃÂ¥[http://www.w3clubs.com/mozdev/httprequest_test.html çÃÂñæÃÂäæøìèéææÃÂìäþÃÂ]ïüÃÂäùÃÂÃÂ¥ÃÂïäûÃÂ¥ÃÂ¥ÃÂÃÂèÃÂÃÂ[http://www.w3clubs.com/mozdev/test.html æøìèéææêÃÂæáÃÂ]ãÃÂà| |
− | == | + | == çììÃÂ¥ÃÂÃÂæÃÂÃÂ¥ âÃÂàãÃÂÃÂX æêÃÂæáÃÂãÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂèÃÂÃÂçÃÂàXML ÃÂ¥ÃÂÃÂæÃÂÃÂÃÂ¥ÃÂüãÃÂÃÂïüà== |
− | + | ÃÂ¥ÃÂÃÂéÃÂâçÃÂÃÂäþÃÂÃÂ¥ÃÂÃÂäøÃÂïüÃÂÃÂ¥ÃÂèæÃÂöÃÂ¥ÃÂð HTTP ÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüÃ¥þÃÂæÃÂÃÂÃÂ¥ÃÂÃÂäûÃ¥çÃÂéäûöçÃÂà<code>reponseText</code> Ã¥ñìæÃÂçäýÿçÃÂè <code>test.html</code> æêÃÂæáÃÂçÃÂÃÂÃÂ¥ÃÂ
çÃ¥îùïüÃÂæÃÂÃ¥èÃÂÃÂäþÃÂèéæèéæ <code>responseXML</code> Ã¥ñìæÃÂççÃÂÃÂæÃÂùæóÃÂãÃÂà| |
− | + | éæÃÂÃÂ¥ÃÂ
ÃÂïüÃÂæÃÂÃÂÃÂ¥ÃÂÃÂÃ¥þÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæàüÃ¥üÃÂæÃÂãçâúçÃÂàXML æÃÂÃÂäûöïüÃÂäûÃ¥äþÿçèÃÂÃ¥þÃÂÃÂ¥ÃÂÃÂçÃÂèãÃÂÃÂæÃÂäæêÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂà<code>test.xml</code>ïüÃÂÃÂ¥ÃÂ
çÃ¥îùÃ¥æÃÂäøÃÂïüà| |
<pre> | <pre> | ||
行 177: | 行 178: | ||
</pre> | </pre> | ||
− | + | ÃÂ¥ÃÂèçèÃÂÃ¥üÃÂäøÃÂïüÃÂæÃÂÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂëçÃÂèæêÃÂæáÃÂçÃÂÃÂÃÂ¥ÃÂðæÃÂùÃÂ¥ÃÂêéàÃÂçÃÂÃ¥äúÃÂäÿîæÃÂùÃ¥æÃÂäøÃÂïüà| |
<pre> | <pre> | ||
行 185: | 行 186: | ||
</pre> | </pre> | ||
− | + | æÃÂÃ¥èÃÂÃÂÃÂ¥ÃÂè <code>alertContents()</code> äøÃÂïüÃÂæÃÂÃÂÃÂ¥ÃÂÃÂÃ¥ÿÃÂ
éàÃÂÃ¥ðà<code>alert(http_request.responseText);</code> æÃÂùæÃÂÃÂéÃÂÃÂæèãïüà| |
<pre> | <pre> | ||
行 193: | 行 194: | ||
</pre> | </pre> | ||
− | + | éÃÂÃÂæèãäøÃÂäþÃÂæÃÂÃÂÃÂ¥ÃÂÃÂäþÿÃÂ¥ÃÂïÃÂ¥ÃÂÃÂÃ¥þà<code>responseXML</code> æÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂà<code>XMLDocument</code> çÃÂéäûöïüÃÂèÃÂÃÂÃ¥þÃÂäûÃÂ¥ DOM çÃÂøéÃÂÃÂçÃÂÃÂæÃÂùæóÃÂÃÂ¥ÃÂÃÂçÃÂè XML æÃÂÃÂäûöÃÂ¥ÃÂ
çÃ¥îùãÃÂÃÂäýàÃÂ¥ÃÂïäûÃÂ¥ÃÂ¥ÃÂÃÂèÃÂà[http://www.w3clubs.com/mozdev/test.xml<code>test.xml</code> çÃÂÃÂÃÂ¥ÃÂÃÂÃ¥çÃÂçâü] äûÃÂ¥ÃÂ¥ÃÂÃÂäÿîæÃÂùéÃÂÃÂÃ¥þÃÂçÃÂÃÂ[http://www.w3clubs.com/mozdev/httprequest_test_xml.html æøìèéæçèÃÂÃ¥üÃÂ]ãÃÂà| |
− | + | ÃÂ¥ÃÂ
öäûÃÂèÃÂàDOM çÃÂøéÃÂÃÂçÃÂÃÂæÃÂùæóÃÂïüÃÂèëÃÂÃÂ¥ÃÂÃÂèÃÂà[http://www.mozilla.org/docs/dom/ Mozilla DOM] æÃÂÃÂäûöãÃÂà| |
<div style="display:none;"> | <div style="display:none;"> | ||
− | [[{{literal2|=Category: | + | [[{{literal2|=Category:æÃÂÃÂäûöÃ¥ðÃÂæáÃÂ|æÃÂÃÂäûöÃ¥ðÃÂæáÃÂ=}}|{{literal2|={{PAGENAME}}|æÃÂÃÂäûöÃ¥ðÃÂæáÃÂ=}}]] |
[[{{literal2|=Category:{{{4}}}|{{{4}}}=}}|{{literal2|={{PAGENAME}}|{{{4}}}=}}]] | [[{{literal2|=Category:{{{4}}}|{{{4}}}=}}|{{literal2|={{PAGENAME}}|{{{4}}}=}}]] | ||
[[{{literal2|=Category:{{{5}}}|{{{5}}}=}}|{{literal2|={{PAGENAME}}|{{{5}}}=}}]] | [[{{literal2|=Category:{{{5}}}|{{{5}}}=}}|{{literal2|={{PAGENAME}}|{{{5}}}=}}]] | ||
行 204: | 行 205: | ||
</div> | </div> | ||
− | <div class="page-nav"><b> | + | <div class="page-nav"><b>âÃÂçèÿÃÂÃÂ¥ÃÂÃÂäøÃÂäøÃÂéàÃÂ: </b>[[éÃÂÃÂçÃÂüäúúÃÂ¥ÃÂáæÃÂÃÂäûöäøûéàÃÂ]]</div> |
於 2009年1月9日 (五) 16:11 的修訂
rock hudson jane wyman movie queensland learners licence test karas xxx free video record flash movies new movie releases to video movie coloring pages james newman videogames jeux video.com panasonic 3ccd video cameras susan selles movie aguilera photo shoot video extreme ops movie cast second x file movie indianmoviesonline prodigy breathe music video
éÃÂÃÂçïÃÂæÃÂÃÂçëàèêêæÃÂàAJAX çÃÂøéÃÂÃÂæÃÂÃÂèáÃÂçÃÂÃÂÃÂ¥ÃÂúçäÃÂïüÃÂäøææÃÂÃÂäþÃÂÃ¥ïæäþÃÂäþÃÂæÃÂèäøÃÂæÃÂÃÂãÃÂÃÂ
內容大綱
- 1 çììäøÃÂæÃÂÃÂ¥ âÃÂàèêêèÃÂòãÃÂÃÂèëÃÂãÃÂàïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂæÃÂÃÂéúüçÃÂüÃÂ¥ÃÂú XMLHttpRequestãÃÂÃÂïüÃÂ
- 2 çììäúÃÂæÃÂÃÂ¥ âÃÂàãÃÂÃÂÃ¥ðñäøÃÂÃÂ¥ÃÂéïüÃÂãÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂèÃÂÃÂçÃÂÃÂäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂèóÃÂæÃÂÃÂãÃÂÃÂïüÃÂ
- 3 çììäøÃÂæÃÂÃÂ¥ - èÃÂìäúÃÂäÿñÃÂ¥ÃÂà- çðáÃÂ¥ÃÂîçïÃÂäþÃÂ
- 4 çììÃÂ¥ÃÂÃÂæÃÂÃÂ¥ âÃÂàãÃÂÃÂX æêÃÂæáÃÂãÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂèÃÂÃÂçÃÂàXML ÃÂ¥ÃÂÃÂæÃÂÃÂÃÂ¥ÃÂüãÃÂÃÂïüÃÂ
çììäøÃÂæÃÂÃÂ¥ âÃÂàèêêèÃÂòãÃÂÃÂèëÃÂãÃÂàïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂæÃÂÃÂéúüçÃÂüÃÂ¥ÃÂú XMLHttpRequestãÃÂÃÂïüÃÂ
çÃÂúäúÃÂçÃÂè JavaScript Ã¥ðÃÂäüúæÃÂÃÂÃÂ¥ÃÂèçÃÂüéÃÂàHTTP èæÃÂæñÃÂïüÃÂÃ¥ÿÃÂ
éàÃÂÃÂ¥ÃÂ
ÃÂäûÃ¥çÃÂøéÃÂÃÂçÃÂÃÂéáÃÂÃÂ¥ÃÂÃ¥ïüÃÂclassïüÃÂèãýÃÂ¥ÃÂúÃ¥ïæéëÃÂïüÃÂinstanceïüÃÂãÃÂÃÂInternet Explorer éæÃÂÃÂ¥ÃÂ
ÃÂäûÃÂ¥ ActiveX çÃÂéäûöæÃÂùÃ¥üÃÂæÃÂÃÂäþàXMLHTTP
éáÃÂÃÂ¥ÃÂÃ¥ïüÃÂèÃÂàMozillaãÃÂÃÂSafari ÃÂ¥ÃÂÃÂÃÂ¥ÃÂ
öäûÃÂçÃÂÃÂèæýÃÂ¥ÃÂèÃÂ¥ÃÂÃÂéÃÂèÃ¥þÃÂäûÃÂ¥ XMLHttpRequest
éáÃÂÃÂ¥ÃÂÃ¥æÃÂïæÃÂôæÃÂä ActiveX çÃÂéäûöäøÃÂçÃÂÃÂéáÃÂÃÂ¥ÃÂÃÂ¥ÃÂ¥ÃÂÃÂÃ¥ñìæÃÂçãÃÂÃÂ
ÃÂ¥ÃÂàæÃÂäïüÃÂÃ¥æÃÂæÃÂÃÂæÃÂóè÷èçÃÂÃÂèæýÃÂ¥ÃÂèïüÃÂéÃÂãéúüÃÂ¥ÃÂïäûÃ¥éÃÂÃÂéúüÃ¥ïëïüÃÂ
if (window.XMLHttpRequest) { // Mozilla, Safari, ... http_request = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE http_request = new ActiveXObject("Microsoft.XMLHTTP"); }
(çÃÂñæÃÂüéÃÂÃÂæîõçèÃÂÃ¥üÃÂÃÂ¥ÃÂàäþÃÂèêêæÃÂÃÂïüÃÂæÃÂÃÂäûÃ¥æÃÂïæÃÂáæÃÂÃÂçðáæÃÂùÃ¥üÃÂÃ¥ïëÃÂ¥ÃÂúãÃÂÃÂæÃÂìæÃÂÃÂçììäøÃÂæÃÂÃ¥äøÃÂæÃÂÃÂÃÂ¥ÃÂæäøÃÂçèîæÃÂÃÂÃÂ¥ÃÂÃÂæïÃÂèüÃÂÃ¥øøçÃÂèçÃÂÃÂÃ¥ïëæóÃÂãÃÂÃÂ)
æÃÂÃÂäúÃÂçÃÂÃÂæÃÂìçÃÂàMozilla çÃÂÃÂèæýÃÂ¥ÃÂèÃÂ¥ÃÂèäüúæÃÂÃÂÃÂ¥ÃÂèéÃÂÃÂÃÂ¥ÃÂÃÂçÃÂÃÂèóÃÂæÃÂÃÂæÃÂêÃÂ¥ÃÂë XML mime-type æêÃÂéàÃÂïüÃÂheaderïüÃÂæÃÂÃÂæÃÂÃÂÃÂ¥ÃÂúéÃÂïãÃÂÃÂçÃÂúäúÃÂéÃÂÿÃÂ¥ÃÂ
ÃÂéÃÂÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂéáÃÂïüÃÂäýàÃÂ¥ÃÂïäûÃ¥çÃÂèäøÃÂÃÂ¥ÃÂÃÂæÃÂùæóÃÂèæÃÂÃ¥ïëäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂæêÃÂéàÃÂïüÃÂäûÃÂ¥ÃÂ¥ÃÂ
ÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂäøÃÂæÃÂï text/xml
ãÃÂÃÂ
http_request = new XMLHttpRequest(); http_request.overrideMimeType('text/xml');
æÃÂÃ¥äøÃÂäþÃÂæÃÂïèæÃÂæñúÃ¥îÃÂäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂèóÃÂæÃÂÃÂÃ¥þÃÂçÃÂÃÂèÃÂÃÂçÃÂÃÂæÃÂùÃ¥üÃÂïüÃÂæÃÂäæÃÂÃÂäýàÃÂ¥ÃÂêèæÃÂäûÃÂ¥ onreadystatechange
éÃÂÃÂÃÂ¥ÃÂÃÂÃ¥ñìæÃÂçæÃÂÃÂæÃÂÃÂèæÃÂèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüçÃÂàJavaScript ÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñÃÂ¥ÃÂóÃÂ¥ÃÂïïüÃÂäþÃÂÃ¥æÃÂïüÃÂ
http_request.onreadystatechange = nameOfTheFunction;
æóèæÃÂÃÂïüÃÂæÃÂÃÂÃ¥îÃÂçÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñÃ¥þÃÂäøÃÂÃÂ¥ÃÂàæÃÂìèÃÂÃÂäùÃÂæòÃÂæÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøãÃÂÃÂéÃÂääúÃÂæÃÂÃÂÃ¥îÃÂÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñÃ¥äÃÂïüÃÂäýàäùÃÂèÃÂýçÃÂè Javascript ÃÂ¥ÃÂóæÃÂÃÂÃ¥îÃÂçþéÃÂ¥ÃÂýÃ¥üÃÂçÃÂÃÂæÃÂùæóÃÂäþÃÂÃ¥îÃÂäøÃÂÃÂ¥ÃÂÃÂæÃÂðçÃÂÃÂèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂïüÃÂÃ¥æÃÂäøÃÂïüÃÂ
http_request.onreadystatechange = function(){ // ÃÂ¥ÃÂÃÂäúÃÂäúà};
æñúÃ¥îÃÂèÃÂÃÂçÃÂÃÂæÃÂùÃ¥üÃÂäùÃÂÃ¥þÃÂäýàÃ¥þÃÂçâúÃ¥ïæçÃÂüÃÂ¥ÃÂú requestïüÃÂæÃÂäæÃÂÃÂéÃÂÃÂÃÂ¥ÃÂëçÃÂè HTTP request éáÃÂÃÂ¥ÃÂÃ¥çÃÂàopen()
ÃÂ¥ÃÂàsend()
æÃÂùæóÃÂïüÃÂÃ¥æÃÂäøÃÂïüÃÂ
http_request.open('GET', 'http://www.example.org/some.file', true); http_request.send(null);
open()
çÃÂÃÂçììäøÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøæÃÂï HTTP request çÃÂÃÂæÃÂùæóÃÂïüÃÂäùÃÂÃ¥ðñæÃÂïÃ¥þàGETãÃÂÃÂPOSTãÃÂÃÂHEAD äøÃÂæÃÂÃÂäøÃÂäýÿçÃÂèïüÃÂäúæÃÂ¥ÃÂïçÃÂèäýàäøûæéÃÂäøÃÂæÃÂïæÃÂôçÃÂÃÂæÃÂùÃ¥üÃÂãÃÂÃÂçÃÂúéÃÂõÃ¥þê HTTP æèÃÂæúÃÂïüÃÂèëÃÂèèÃÂÃ¥þÃÂéÃÂÃÂäúÃÂæÃÂùæóÃÂéÃÂýæÃÂïÃ¥äçÃ¥ïëïüÃÂäøÃÂçÃÂöæÃÂÃÂçÃÂÃÂçÃÂÃÂèæýÃÂ¥ÃÂèïüÃÂÃ¥æàFirefoxïüÃÂæÃÂÃÂèèñäøÃÂæÃÂÃÂçÃÂÃÂäýàãÃÂÃÂÃ¥àöäûàHTTP request ÃÂ¥ÃÂïäûÃ¥æÃÂïæÃÂôçÃÂÃÂæÃÂùæóÃÂÃÂ¥ÃÂÃÂèáèèëÃÂÃÂ¥ÃÂÃÂèÃÂàW3C èæÃÂæàüæÃÂøãÃÂÃÂ- çììäúÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøæÃÂïçÃÂîæèàURLãÃÂÃÂÃÂ¥ÃÂúæÃÂüÃ¥îÃÂÃÂ¥ÃÂ
èèÃÂÃÂéÃÂÃÂïüÃÂäýàäøÃÂèÃÂýÃÂ¥ÃÂëçÃÂèÃÂ¥ÃÂÃÂçöòÃÂ¥ÃÂÃÂäûÃ¥åäÃÂçÃÂÃÂçöòéàÃÂãÃÂÃÂÃ¥æÃÂæÃÂÃÂçöòÃÂ¥ÃÂÃÂäøÃÂÃÂ¥ÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂëçÃÂè
open()
æÃÂÃÂæÃÂÃÂÃÂ¥ÃÂúçÃÂþãÃÂÃÂæìÃÂéÃÂÃÂäøÃÂèöóïüÃÂæÃÂÃÂçõÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂãÃÂÃÂéÃÂãéáÃÂçÃÂÃÂéÃÂïèêäãÃÂÃÂéÃÂÃÂÃ¥øøÃ¥äçÃ¥äÃ¥æÃÂÃÂçÃÂïçÃÂÃÂéÃÂïèêäÃ¥äÃÂçÃÂúÃÂ¥ÃÂè domain.tld çöòçÃÂÃÂçöòçëÃÂäøÃÂÃÂ¥ÃÂüÃÂ¥ÃÂë www.domain.tld äøÃÂçÃÂÃÂçöòéàÃÂïüÃÂÃÂ¥ÃÂàæÃÂïäøÃÂéûÃÂéûÃÂÃ¥÷îÃÂ¥ÃÂÃ¥éÃÂýäøÃÂèáÃÂãÃÂà- çììäøÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøæñúÃ¥îÃÂæÃÂä request æÃÂïÃÂ¥ÃÂæäøÃÂÃÂ¥ÃÂÃÂæÃÂÃ¥éÃÂòèáÃÂïüÃÂÃ¥æÃÂæÃÂÃÂèèÃÂÃ¥îÃÂçÃÂú
TRUE
ÃÂ¥ÃÂÃÂÃÂ¥ÃÂóäýÿäüúæÃÂÃÂÃÂ¥ÃÂèÃ¥ðÃÂæÃÂêÃÂ¥ÃÂóÃÂ¥ÃÂÃÂèóÃÂæÃÂÃÂäùÃÂæÃÂÃÂçùüçúÃÂÃÂ¥ÃÂ÷èáÃÂÃ¥àöéäÃÂçÃÂÃÂçèÃÂÃ¥üÃÂïüÃÂéÃÂÃÂäùÃÂÃ¥ðñæÃÂï AJAX äøÃÂçììäøÃÂÃÂ¥ÃÂàA äûãèáèçÃÂÃÂæÃÂÃÂçþéãÃÂÃÂ
send()
çÃÂÃÂÃÂ¥ÃÂÃÂæÃÂøÃÂ¥ÃÂèäûÃÂ¥ POST çÃÂüÃÂ¥ÃÂú request æÃÂÃÂÃÂ¥ÃÂïäûÃ¥æÃÂïäûûäýÃÂæÃÂóÃÂ¥ÃÂóçõæäüúæÃÂÃÂÃÂ¥ÃÂèçÃÂÃÂæÃÂñèÃ¥ÿïüÃÂèÃÂÃÂèóÃÂæÃÂÃÂÃÂ¥ÃÂÃÂäûÃ¥æÃÂÃ¥èéâÃÂ¥ÃÂÃÂäøòçÃÂÃÂæÃÂùÃ¥üÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂúïüÃÂäþÃÂÃ¥æÃÂïüÃÂ
name=value&anothername=othervalue&so=on
äøÃÂéÃÂÃÂÃ¥æÃÂæÃÂÃÂäýàæÃÂóèæÃÂäûÃÂ¥ POST æÃÂùÃ¥üÃÂÃÂ¥ÃÂóéÃÂÃÂèóÃÂæÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂÃ¥ÿàéàÃÂÃ¥àÃÂÃ¥ðàMIME ÃÂ¥ÃÂÃÂæàÃÂæÃÂùÃ¥åýïüÃÂÃ¥æÃÂäøÃÂïüÃÂ
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ÃÂ¥ÃÂæÃÂ¥ÃÂÃÂäüúæÃÂÃÂÃÂ¥ÃÂèÃ¥ðñäøÃÂæÃÂÃÂçÃÂÃÂäýàÃÂ¥ÃÂóéÃÂÃÂäþÃÂçÃÂÃÂèóÃÂæÃÂÃÂäúÃÂãÃÂÃÂ
çììäúÃÂæÃÂÃÂ¥ âÃÂàãÃÂÃÂÃ¥ðñäøÃÂÃÂ¥ÃÂéïüÃÂãÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂèÃÂÃÂçÃÂÃÂäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂèóÃÂæÃÂÃÂãÃÂÃÂïüÃÂ
ÃÂ¥ÃÂóÃÂ¥ÃÂú request æÃÂÃÂÃ¥ÿàéàÃÂæÃÂÃÂäþÃÂèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüçÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂÃÂ¥ÃÂÃÂçèñãÃÂÃÂ
http_request.onreadystatechange = nameOfTheFunction;
éÃÂãéúüäþÃÂçÃÂÃÂçÃÂÃÂéÃÂÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂèéòÃÂ¥ÃÂÃÂäúÃÂäûÃÂéúüãÃÂÃÂéæÃÂÃ¥àÃÂïüÃÂÃ¥îÃÂÃ¥ÿàéàÃÂæêâæÃÂÃÂ¥ request çÃÂîÃÂ¥ÃÂÃÂçÃÂÃÂçÃÂÃÂæàÃÂïüÃÂÃ¥æÃÂæÃÂÃÂçÃÂÃÂæàÃÂÃÂ¥ÃÂüçÃÂú 4 äûãèáèäüúæÃÂÃÂÃÂ¥ÃÂèÃ¥÷òçöÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂæÃÂÃÂæÃÂÃÂèóÃÂèèÃÂäúÃÂïüÃÂäþÿÃÂ¥ÃÂïäûÃ¥éÃÂÃÂÃ¥çÃÂèçãæÃÂÃÂæÃÂÃÂÃ¥þÃÂèóÃÂèèÃÂãÃÂÃÂ
if (http_request.readyState == 4) { // äøÃÂÃÂ¥ÃÂàok, çùüçúÃÂèçãæÃÂà} else { // éÃÂÃÂæòÃÂÃ¥îÃÂæÃÂà}
readyState
æÃÂÃÂæÃÂÃÂÃÂ¥ÃÂïèÃÂýçÃÂÃÂÃÂ¥ÃÂüÃ¥æÃÂäøÃÂïüÃÂ
- 0 (éÃÂÃÂæòÃÂéÃÂÃÂÃ¥çÃÂ)
- 1 (èîÃÂÃÂ¥ÃÂÃÂäøÃÂ)
- 2 (Ã¥÷òèîÃÂÃÂ¥ÃÂÃÂ)
- 3 (èóÃÂèèÃÂäúäæÃÂÃÂäøÃÂ)
- 4 (äøÃÂÃÂ¥ÃÂÃÂÃ¥îÃÂæÃÂÃÂ)
(èóÃÂæÃÂÃÂäþÃÂæúÃÂ: MSDN)
æÃÂÃ¥äøÃÂäþÃÂèæÃÂæêâæÃÂÃ¥äüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂàHTTP çÃÂÃÂæÃÂ
ÃÂçâüãÃÂÃÂæÃÂÃÂæÃÂÃÂçÃÂÃÂæÃÂ
ÃÂçâüÃÂ¥ÃÂÃÂèáèÃÂ¥ÃÂïæÃÂü W3C çöòçëÃÂäøÃÂæÃÂÃÂ¥ÃÂ¥ÃÂðïüÃÂäýÃÂæÃÂÃÂÃÂ¥ÃÂÃÂèæÃÂçîáçÃÂÃÂæÃÂï 200 OK
éÃÂÃÂçèîçÃÂÃÂæÃÂ
ÃÂãÃÂÃÂ
if (http_request.status == 200) { // èÃÂìäúÃÂÃ¥à÷ÃÂ¥ÃÂà} else { // äüüäùÃÂæÃÂÃÂéûÃÂÃÂ¥ÃÂÃÂéáÃÂïüÃÂæÃÂÃÂèèñäüúæÃÂÃÂÃÂ¥ÃÂèÃÂ¥ÃÂóÃÂ¥ÃÂÃÂäúà404 (æÃÂÃ¥çÃÂáæÃÂäéàÃÂ) æÃÂÃÂèÃÂà500 (Ã¥àçéÃÂèéÃÂïèêä) äûÃÂéúüçÃÂà}
æêâæÃÂÃÂ¥ÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂàHTTP çÃÂÃÂæàÃÂçâüÃ¥þÃÂïüÃÂèæÃÂæÃÂÃÂéúüèÃÂÃÂçÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂÃÂèóÃÂæÃÂÃÂÃ¥ðñçÃÂñäýàæñúÃ¥îÃÂäúÃÂãÃÂÃÂæÃÂÃÂÃ¥àéçèîÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂèóÃÂæÃÂÃÂçÃÂÃÂæÃÂùÃ¥üÃÂïüÃÂ
http_request.responseText
âÃÂàéÃÂÃÂæèãæÃÂÃÂæÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüçÃÂöÃÂ¥ÃÂÃÂäøòçÃÂèhttp_request.responseXML
âÃÂàéÃÂÃÂæèãæÃÂÃÂæÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüèæÃÂçÃÂúXMLDocument
çÃÂéäûöïüÃÂèÃÂÃÂÃ¥þÃÂÃÂ¥ÃÂïçÃÂè JavaScript DOM çÃÂøéÃÂÃÂÃÂ¥ÃÂýÃ¥üÃÂèÃÂÃÂçÃÂÃÂ
çììäøÃÂæÃÂÃÂ¥ - èÃÂìäúÃÂäÿñÃÂ¥ÃÂà- çðáÃÂ¥ÃÂîçïÃÂäþÃÂ
Ã¥åýïüÃÂæÃÂÃ¥èÃÂÃÂÃ¥ðñÃÂ¥ÃÂÃÂäøÃÂæìáçðáÃÂ¥ÃÂîçÃÂàHTTP çïÃÂäþÃÂïüÃÂæüÃÂçäúæÃÂùæÃÂÃÂçÃÂÃÂÃÂ¥ÃÂÃÂéàÃÂ
æÃÂÃÂÃ¥÷çãÃÂÃÂéÃÂÃÂæîõ JavaScript æÃÂÃÂÃÂ¥ÃÂÃÂäüúæÃÂÃÂÃÂ¥ÃÂèèæÃÂäøÃÂäûýèãáéàÃÂæÃÂÃÂãÃÂÃÂI'm a test.ãÃÂÃÂÃÂ¥ÃÂÃÂæèãçÃÂàHTML æÃÂÃÂäûö(test.html
)ïüÃÂèÃÂÃÂÃ¥þÃÂäûÃÂ¥ alert()
Ã¥ðÃÂæÃÂÃÂäûöÃÂ¥ÃÂ
çÃ¥îùÃÂ¥ÃÂÃÂÃÂ¥ÃÂúãÃÂÃÂ
<script type="text/javascript" language="javascript"> var http_request = false; function makeRequest(url) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('GET', url, true); http_request.send(null); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { alert(http_request.responseText); } else { alert('There was a problem with the request.'); } } } </script> <span style="cursor: pointer; text-decoration: underline" onclick="makeRequest('test.html')"> Make a request </span>
ÃÂ¥ÃÂèæÃÂäçïÃÂäþÃÂäøÃÂïüÃÂ
- éæÃÂÃ¥àÃÂäýÿçÃÂèèÃÂàæÃÂÃÂäøÃÂãÃÂÃÂMake a requestãÃÂÃÂ
- éÃÂÃÂéúüäøÃÂäþÃÂÃ¥ðñæÃÂÃÂÃÂ¥ÃÂüÃÂ¥ÃÂë
makeRequest()
ÃÂ¥ÃÂýÃ¥üÃÂïüÃÂäúæÃÂ¥ÃÂóÃ¥àÃÂ¥ÃÂ¥ÃÂÃÂæÃÂøÃÂ¥ÃÂütest.html
(äùÃÂÃ¥ðñæÃÂïéÃÂãäûý HTML æêÃÂçÃÂÃÂÃÂ¥ÃÂÃÂçèñïüÃÂæÃÂþÃÂ¥ÃÂèÃÂ¥ÃÂÃÂçÃÂîéÃÂÃÂäøÃÂ) - æÃÂÃ¥èÃÂÃÂçÃÂüÃÂ¥ÃÂú requestïüÃÂèÃÂÃÂÃ¥þÃÂæÃÂÃÂÃ¥ðÃÂäøûÃ¥ðÃÂæìÃÂäúäçõæ
onreadystatechange
æÃÂÃÂÃ¥îÃÂçÃÂÃÂalertContents()
ÃÂ¥ÃÂýÃ¥üàalertContents()
æêâæÃÂÃÂ¥ÃÂ¥ÃÂÃÂæÃÂÃÂæÃÂïÃÂ¥ÃÂææÃÂãÃ¥øøïüÃÂèÃÂÃÂÃ¥þÃÂäûÃÂ¥alert()
Ã¥ðÃÂtest.html
çÃÂÃÂÃ¥àçÃ¥îùÃÂ¥ÃÂÃÂÃÂ¥ÃÂú
äýàÃÂ¥ÃÂïäûÃ¥çÃÂñæÃÂäæøìèéææÃÂìäþÃÂïüÃÂäùÃÂÃÂ¥ÃÂïäûÃÂ¥ÃÂ¥ÃÂÃÂèÃÂÃÂæøìèéææêÃÂæáÃÂãÃÂÃÂ
çììÃÂ¥ÃÂÃÂæÃÂÃÂ¥ âÃÂàãÃÂÃÂX æêÃÂæáÃÂãÃÂÃÂïüÃÂÃÂ¥ÃÂÃÂçèñçÃÂúãÃÂÃÂèÃÂÃÂçÃÂàXML ÃÂ¥ÃÂÃÂæÃÂÃÂÃÂ¥ÃÂüãÃÂÃÂïüÃÂ
ÃÂ¥ÃÂÃÂéÃÂâçÃÂÃÂäþÃÂÃÂ¥ÃÂÃÂäøÃÂïüÃÂÃÂ¥ÃÂèæÃÂöÃÂ¥ÃÂð HTTP ÃÂ¥ÃÂóÃÂ¥ÃÂÃÂÃÂ¥ÃÂüÃ¥þÃÂæÃÂÃÂÃÂ¥ÃÂÃÂäûÃ¥çÃÂéäûöçÃÂàreponseText
Ã¥ñìæÃÂçäýÿçÃÂè test.html
æêÃÂæáÃÂçÃÂÃÂÃÂ¥ÃÂ
çÃ¥îùïüÃÂæÃÂÃ¥èÃÂÃÂäþÃÂèéæèéæ responseXML
Ã¥ñìæÃÂççÃÂÃÂæÃÂùæóÃÂãÃÂÃÂ
éæÃÂÃÂ¥ÃÂ
ÃÂïüÃÂæÃÂÃÂÃÂ¥ÃÂÃÂÃ¥þÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂÃÂæàüÃ¥üÃÂæÃÂãçâúçÃÂàXML æÃÂÃÂäûöïüÃÂäûÃ¥äþÿçèÃÂÃ¥þÃÂÃÂ¥ÃÂÃÂçÃÂèãÃÂÃÂæÃÂäæêÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂàtest.xml
ïüÃÂÃÂ¥ÃÂ
çÃ¥îùÃ¥æÃÂäøÃÂïüÃÂ
<?xml version="1.0" ?> <root> I'm a test. </root>
ÃÂ¥ÃÂèçèÃÂÃ¥üÃÂäøÃÂïüÃÂæÃÂÃÂÃÂ¥ÃÂÃÂÃÂ¥ÃÂëçÃÂèæêÃÂæáÃÂçÃÂÃÂÃÂ¥ÃÂðæÃÂùÃÂ¥ÃÂêéàÃÂçÃÂÃ¥äúÃÂäÿîæÃÂùÃ¥æÃÂäøÃÂïüÃÂ
... onclick="makeRequest('test.xml')"> ...
æÃÂÃ¥èÃÂÃÂÃÂ¥ÃÂè alertContents()
äøÃÂïüÃÂæÃÂÃÂÃÂ¥ÃÂÃÂÃ¥ÿÃÂ
éàÃÂÃ¥ðàalert(http_request.responseText);
æÃÂùæÃÂÃÂéÃÂÃÂæèãïüÃÂ
var xmldoc = http_request.responseXML; var root_node = xmldoc.getElementsByTagName('root').item(0); alert(root_node.firstChild.data);
éÃÂÃÂæèãäøÃÂäþÃÂæÃÂÃÂÃÂ¥ÃÂÃÂäþÿÃÂ¥ÃÂïÃÂ¥ÃÂÃÂÃ¥þàresponseXML
æÃÂÃÂÃÂ¥ÃÂóÃÂ¥ÃÂÃÂçÃÂàXMLDocument
çÃÂéäûöïüÃÂèÃÂÃÂÃ¥þÃÂäûÃÂ¥ DOM çÃÂøéÃÂÃÂçÃÂÃÂæÃÂùæóÃÂÃÂ¥ÃÂÃÂçÃÂè XML æÃÂÃÂäûöÃÂ¥ÃÂ
çÃ¥îùãÃÂÃÂäýàÃÂ¥ÃÂïäûÃÂ¥ÃÂ¥ÃÂÃÂèÃÂàtest.xml
çÃÂÃÂÃÂ¥ÃÂÃÂÃ¥çÃÂçâü äûÃÂ¥ÃÂ¥ÃÂÃÂäÿîæÃÂùéÃÂÃÂÃ¥þÃÂçÃÂÃÂæøìèéæçèÃÂÃ¥üÃÂãÃÂÃÂ
Ã¥àöäûÃÂèÃÂàDOM çÃÂøéÃÂÃÂçÃÂÃÂæÃÂùæóÃÂïüÃÂèëÃÂÃÂ¥ÃÂÃÂèÃÂàMozilla DOM æÃÂÃÂäûöãÃÂÃÂ