锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美激情影院,亚洲国产精品久久久天堂,亚洲播播91http://www.aygfsteel.com/paulwong/category/10812.htmlzh-cnWed, 28 Feb 2007 21:11:48 GMTWed, 28 Feb 2007 21:11:48 GMT60- AJAX 涓婃墜綃?/title><link>http://www.aygfsteel.com/paulwong/articles/44684.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 05 May 2006 14:21:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/articles/44684.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/44684.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/articles/44684.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/44684.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/44684.html</trackback:ping><description><![CDATA[
<h1>AJAX 涓婃墜綃?o:p></o:p></h1>
<o:p>
</o:p>
<h2>絎竴姝?鈥?璇村0銆岃銆?錛堝張縐頒負銆屾€庝箞鍙戝嚭 XMLHttpRequest銆嶏級 <o:p></o:p></h2>
<p>涓轟簡鐢?JavaScript 瀵規湇鍔″櫒鍙戦€?HTTP 瑕佹眰錛屼綘蹇呴』鍏堜互鐩稿叧鐨勭被鍒紙class錛夊埗鍑哄疄浣擄紙instance錛夈€侷nternet<br />Explorer 棣栧厛浠?ActiveX 瀵硅薄鏂瑰紡鎻愪緵 <code>XMLHTTP</code> 綾誨埆錛岃€?Mozilla銆丼afari鍙婂叾瀹冩祻瑙堝櫒鍒欓殢鍚庝互 <code>XMLHttpRequest</code> 綾誨埆鏀寔姝?ActiveX 瀵硅薄涓殑綾誨埆鍙婂睘鎬с€?<o:p></o:p></p>
<br />
<p>鍥犳錛屽鏋滄兂璺ㄦ祻瑙堝櫒錛岄偅涔堝彲浠ヨ繖涔堝啓錛毬?/p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(window.XMLHttpRequest)聽{聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽Mozilla,聽Safari,聽<img src="http://www.aygfsteel.com/images/dot.gif" /></span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />聽聽聽聽http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">new</span>
<span style="color: rgb(0, 0, 0);">聽XMLHttpRequest();<br /><br />}聽</span>
<span style="color: rgb(0, 0, 255);">else</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(window.ActiveXObject)聽{聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽IE</span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />聽聽聽聽http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">new</span>
<span style="color: rgb(0, 0, 0);">聽ActiveXObject(</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">Microsoft.XMLHTTP</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">);<br /><br />}<br /><br /></span>
</div>
<o:p>
</o:p>
<p>
<br />
</p>
<p>(鐢變簬榪欐紼嬪簭浠呬緵璇存槑錛屾墍浠ユ槸閲囨渶綆€鏂瑰紡鍐欏嚭銆傛湰鏂囩涓夋涓湁鍙︿竴縐嶆垜浠瘮杈冨父鐢ㄧ殑鍐欐硶銆? <o:p></o:p></p>
<p>鏈変簺鐗堟湰鐨?Mozilla 嫻忚鍣ㄥ湪鏈嶅姟鍣ㄩ€佸洖鐨勬暟鎹湭鍚?XML mime-type 鏂囦歡澶達紙header錛夋椂浼氬嚭閿欍€備負浜嗛伩鍏嶈繖涓棶棰橈紝浣犲彲浠ョ敤涓嬪垪鏂規硶瑕嗗啓鏈嶅姟鍣ㄤ紶鍥炵殑妗eご錛屼互鍏嶄紶鍥炵殑涓嶆槸<code>text/xml</code>銆?/p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">new</span>
<span style="color: rgb(0, 0, 0);">聽XMLHttpRequest();<br /><br />http_request.overrideMimeType('text</span>
<span style="color: rgb(0, 0, 0);">/</span>
<span style="color: rgb(0, 0, 0);">xml');</span>
</div>
<o:p>
</o:p>
<p>
<br />
</p>
<p>鎺ヤ笅鏉ユ槸瑕佸喅瀹氭湇鍔″櫒浼犲洖璧勬枡鍚庣殑澶勭悊鏂瑰紡錛屾鏃朵綘鍙浠?<code>onreadystatechange</code> 榪欎釜灞炴€ф寚鏄庤澶勭悊浼犲洖鍊肩殑<br />JavaScript 鍑藉紡鍚嶇О鍗沖彲錛屼緥濡傦細</p>
<p>
<br />
<o:p>
</o:p>
</p>
<p>
<code>
</code>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">http_request.onreadystatechange聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽nameOfTheFunction;</span>
</div>
<br />
<o:p>
</o:p>
<p>
</p>
<p>娉ㄦ剰錛屾寚瀹氱殑鍑藉紡鍚嶇О鍚庝笉鍔犳嫭鍙蜂篃娌℃湁鍙傛暟銆傞櫎浜嗘寚瀹氬嚱寮忓悕縐板錛屼綘涔熻兘鐢?Javascript 瀹炴椂瀹氫箟鍑藉紡鐨勬柟娉曟潵瀹氫竴涓柊鐨勫鐞嗗嚱寮忥紝濡備笅錛?/p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">http_request.onreadystatechange聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">function</span>
<span style="color: rgb(0, 0, 0);">(){<br /><br />聽聽聽聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽鍋氫簺浜?/span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />};</span>
</div>
<o:p>
</o:p>
<p>
<br />
</p>
<p>鍐沖畾澶勭悊鏂瑰紡涔嬪悗浣犲緱紜疄鍙戝嚭 request錛屾鏃墮渶鍙敤 HTTP request 綾誨埆鐨?<code>open()</code> 鍙?<code>send()</code> 鏂規硶錛屽涓嬶細</p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">http_request.open('GET',聽'http:</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">www.example.org/some.file',聽true);</span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">http_request.send(</span>
<span style="color: rgb(0, 0, 255);">null</span>
<span style="color: rgb(0, 0, 0);">);<br /><br /></span>
</div>
<o:p>
</o:p>
<ul type="disc">
<li id="wmqeeuq" class="MsoNormal">
<code>open()</code> 鐨勭涓€涓弬鏁版槸<br />聽聽聽聽 HTTP request 鐨勬柟娉曪紝涔熷氨鏄粠<br />聽聽聽聽 GET銆丳OST銆丠EAD 涓嫨涓€浣跨敤錛屼害鍙敤浣犱富鏈轟笂鏀寔鐨勬柟寮忋€備負閬靛驚 HTTP 鏍囧噯錛岃璁板緱榪欎簺鏂規硶閮芥槸澶у啓錛屼笉鐒舵湁鐨勬祻瑙堝櫒錛堝 Firefox錛夋垨璁鎬笉浼氱悊浣犮€傚叾瀹?HTTP request 鍙互鏀寔鐨勬柟娉曞垪琛ㄨ鍙傝€?br />聽聽聽聽 <a target="_blank">W3C 瑙勬牸涔?/a> (<i><a target="_blank" >http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html</a></i>)銆?<o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">絎簩涓弬鏁版槸鐩爣 URL銆傚熀浜庡畨鍏ㄨ€冭檻錛屼綘涓嶈兘鍙敤鍚岀綉鍩熶互澶栫殑緗戦〉銆傚鏋滅綉鍩熶笉鍚岋紝鍒欏彨鐢?br />聽聽聽聽 <code>open()</code> 鏃朵細鍑虹幇銆屾潈闄愪笉瓚籌紝鎷掔粷瀛樺彇銆嶉偅綾葷殑閿欒銆傞€氬父澶т紮浼氱姱鐨勯敊璇涓哄湪 domain.tld 緗戠殑緗戠珯涓嬪懠鍙?<a target="_blank" >www.domain.tld</a> 涓殑緗戦〉錛屼粎鏄竴鐐圭偣宸埆閮戒笉琛屻€?br />聽聽聽聽 <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">絎笁涓弬鏁板喅瀹氭 request 鏄惁涓嶅悓姝ヨ繘琛岋紝濡傛灉璁懼畾涓?br />聽聽聽聽 <code>TRUE</code> 鍒欏嵆浣挎湇鍔″櫒灝氭湭浼犲洖鏁版嵁涔熶細緇х畫鎵ц鍏朵綑鐨勭▼搴忥紝榪欎篃灝辨槸 AJAX 涓涓€涓?A 浠h〃鐨勬剰涔夈€?<o:p></o:p></li>
</ul>
<p>
<code>send()</code> 鐨勫弬鏁板湪浠?POST 鍙戝嚭 request 鏃跺彲浠ユ槸浠諱綍鎯充紶緇欐湇鍔″櫒鐨勪笢瑗匡紝鑰屾暟鎹垯浠ユ煡璇㈠瓧絎︿覆鐨勬柟寮忓垪鍑猴紝渚嬪錛?<o:p></o:p></p>
<p>
<code>
</code>聽</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">name</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">value</span>
<span style="color: rgb(0, 0, 0);">&</span>
<span style="color: rgb(0, 0, 0);">anothername</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">othervalue</span>
<span style="color: rgb(0, 0, 0);">&</span>
<span style="color: rgb(0, 0, 0);">so</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">on</span>
</div>
<o:p>
</o:p>
<p>涓嶈繃濡傛灉浣犳兂瑕佷互 POST 鏂瑰紡浼犻€佹暟鎹紝鍒欏繀欏誨厛灝?MIME 鍨嬫€佹敼濂斤紝濡備笅錛?<o:p></o:p></p>
<pre>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">http_request.setRequestHeader('Content</span>
<span style="color: rgb(0, 0, 0);">-</span>
<span style="color: rgb(0, 0, 0);">Type',聽'application</span>
<span style="color: rgb(0, 0, 0);">/</span>
<span style="color: rgb(0, 0, 0);">x</span>
<span style="color: rgb(0, 0, 0);">-</span>
<span style="color: rgb(0, 0, 0);">www</span>
<span style="color: rgb(0, 0, 0);">-</span>
<span style="color: rgb(0, 0, 0);">form</span>
<span style="color: rgb(0, 0, 0);">-</span>
<span style="color: rgb(0, 0, 0);">urlencoded');<br /><br /></span>
</div>
<br />
<o:p>
</o:p>
</pre>
<p>鍚﹀垯鏈嶅姟鍣ㄥ氨涓嶄細鐞嗕綘浼犺繃鏉ョ殑鏁版嵁浜嗐€?<o:p></o:p></p>
<h2>絎簩姝?鈥?銆屽氨涓婂挬錛併€嶏紙鍙堢О涓恒€屽鐞嗘湇鍔″櫒浼犲洖鐨勬暟鎹€嶏級 <o:p></o:p></h2>
<p>浼犲嚭 request 鏃跺繀欏繪彁渚涘鐞嗕紶鍥炲€肩殑鍑藉紡鍚嶇О銆?<o:p></o:p></p>
<p>
<code>
</code>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">http_request.onreadystatechange聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽nameOfTheFunction;</span>
</div>
<br />
<o:p>
</o:p>
<p>
</p>
<pre>////////////////////////////////////////////////////////////////////<o:p></o:p></pre>
<pre>//浣嗘槸錛孎ireFox 瀵筼nreadyStateChange娌℃湁鍙嶅簲錛屾€庝箞鍔烇紝榪欎釜鏂規硶涓嶈兘鐢ㄥ湪<o:p></o:p></pre>
<pre>//FireFox 涓紝鏈夋病鏈夊叾瀹冪殑鏂規硶錛?o:p></o:p></pre>
<pre>//聽聽聽聽聽聽Added by <a target="_blank" >www.besook.com</a> 2006-03-19<o:p></o:p></pre>
<pre>//////////////////////////////////////////////////////////////<o:p></o:p></pre>
<p>閭d箞鏉ョ湅鐪嬭繖涓嚱寮忚鍋氫簺浠€涔堛€傞鍏堬紝瀹冨繀欏繪鏌?request 鐩墠鐨勭姸鎬侊細濡傛灉鐘舵€佸€間負 4 浠h〃鏈嶅姟鍣ㄥ凡緇忎紶鍥炴墍鏈変俊鎭簡錛屼究鍙互寮€濮嬭В鏋愭墍寰椾俊鎭€?/p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(http_request.readyState聽</span>
<span style="color: rgb(0, 0, 0);">==</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 0);">4</span>
<span style="color: rgb(0, 0, 0);">)聽{<br /><br />聽聽聽聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽涓€鍒嚶爋k,聽緇х畫瑙f瀽</span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />}聽</span>
<span style="color: rgb(0, 0, 255);">else</span>
<span style="color: rgb(0, 0, 0);">聽{<br /><br />聽聽聽聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽榪樻病瀹屾垚</span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />}</span>
</div>
<o:p>
</o:p>
<p>
<code>
<br />
</code>
</p>
<p>
<code>readyState</code> 鎵€鏈夊彲鑳界殑鍊煎涓嬶細 <o:p></o:p></p>
<ul type="disc">
<li id="wmqeeuq" class="MsoNormal">0 (榪樻病寮€濮? <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">1 (璇誨彇涓? <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">2 (宸茶鍙? <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">3 (淇℃伅浜ゆ崲涓? <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">4 (涓€鍒囧畬鎴? <o:p></o:p></li>
</ul>
<p>(<a target="_blank">璧勬枡鏉ユ簮: MSDN</a> (<i><a target="_blank" >http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/readystate_1.asp</a></i>))<br /><o:p></o:p></p>
<p>鎺ヤ笅鏉ヨ媯€鏌ユ湇鍔″櫒浼犲洖鐨?HTTP 鐘舵€佺爜銆傛墍鏈夌姸鎬佺爜鍒楄〃鍙簬 <a target="_blank">W3C<br />緗戠珯</a> (<i><a target="_blank" >http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html</a></i>)涓婃煡鍒幫紝浣嗘垜浠綆$殑鏄?code>200 OK</code> 榪欑鐘舵€併€?/p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(http_request.status聽</span>
<span style="color: rgb(0, 0, 0);">==</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 0);">200</span>
<span style="color: rgb(0, 0, 0);">)聽{<br /><br />聽聽聽聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽涓囦簨鍏峰</span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />}聽</span>
<span style="color: rgb(0, 0, 255);">else</span>
<span style="color: rgb(0, 0, 0);">聽{<br /><br />聽聽聽聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽浼間箮鏈夌偣闂錛屾垨璁告湇鍔″櫒浼犲洖浜喡?04聽(鏌ユ棤姝ら〉)聽鎴栬€吢?00聽(鍐呴儴閿欒)聽浠€涔堢殑</span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />}</span>
</div>
<o:p>
</o:p>
<p>
<br />
</p>
<p>
<br />
</p>
<p>媯€鏌ヤ紶鍥炵殑 HTTP 鐘舵€佺爜鍚庯紝瑕佹€庝箞澶勭悊浼犲洖鐨勬暟鎹氨鐢變綘鍐沖畾浜嗐€傛湁涓ょ瀛樺彇鏁版嵁鐨勬柟寮忥細 <o:p></o:p></p>
<ul type="disc">
<li id="wmqeeuq" class="MsoNormal">
<code>http_request.responseText</code> 鈥?榪欐牱浼氭妸浼犲洖鍊煎綋瀛楃涓茬敤<br />聽聽聽聽 <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">
<code>http_request.responseXML</code> 鈥?榪欐牱浼氭妸浼犲洖鍊艱涓?br />聽聽聽聽 <code>XMLDocument</code> 瀵硅薄錛岃€屽悗鍙敤<br />聽聽聽聽 JavaScript DOM 鐩稿叧鍑藉紡澶勭悊 <o:p></o:p></li>
</ul>
<h2>絎笁姝?- 涓囦簨淇卞 - 綆€鍗曡寖渚?<o:p></o:p></h2>
<p>濂斤紝鎺ョ潃灝卞仛涓€嬈$畝鍗曠殑 HTTP 鑼冧緥錛屾紨紺烘柟鎵嶇殑鍚勯」鎶€宸с€傝繖孌?JavaScript 浼氬悜鏈嶅姟鍣ㄨ涓€浠介噷澶存湁銆孖'm<br />a test.銆嶅瓧鏍風殑 HTML 鏂囦歡(<code>test.html</code>)錛岃€屽悗浠?<code>alert()</code> 灝嗘枃浠跺唴瀹瑰垪鍑恒€?/p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);"><</span>
<span style="color: rgb(0, 0, 0);">script聽type</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">text/javascript</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">聽language</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">javascript</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">></span>
<span style="color: rgb(0, 0, 0);">
<br />
<br />聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">var</span>
<span style="color: rgb(0, 0, 0);">聽http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">false</span>
<span style="color: rgb(0, 0, 0);">;<br /><br />聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">function</span>
<span style="color: rgb(0, 0, 0);">聽makeRequest(url)聽{<br /><br />聽聽聽聽聽聽聽聽http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">false</span>
<span style="color: rgb(0, 0, 0);">;<br /><br />聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(window.XMLHttpRequest)聽{聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽Mozilla,聽Safari,<img src="http://www.aygfsteel.com/images/dot.gif" /></span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />聽聽聽聽聽聽聽聽聽聽聽聽http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">new</span>
<span style="color: rgb(0, 0, 0);">聽XMLHttpRequest();<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(http_request.overrideMimeType)聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽http_request.overrideMimeType('text</span>
<span style="color: rgb(0, 0, 0);">/</span>
<span style="color: rgb(0, 0, 0);">xml');<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽}<br /><br />聽聽聽聽聽聽聽聽}聽</span>
<span style="color: rgb(0, 0, 255);">else</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(window.ActiveXObject)聽{聽</span>
<span style="color: rgb(0, 128, 0);">//</span>
<span style="color: rgb(0, 128, 0);">聽IE</span>
<span style="color: rgb(0, 128, 0);">
<br />
</span>
<span style="color: rgb(0, 0, 0);">
<br />聽聽聽聽聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">try</span>
<span style="color: rgb(0, 0, 0);">聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">new</span>
<span style="color: rgb(0, 0, 0);">聽ActiveXObject(</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">Msxml2.XMLHTTP</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">);<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽}聽</span>
<span style="color: rgb(0, 0, 255);">catch</span>
<span style="color: rgb(0, 0, 0);">聽(e)聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">try</span>
<span style="color: rgb(0, 0, 0);">聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽http_request聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">new</span>
<span style="color: rgb(0, 0, 0);">聽ActiveXObject(</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">Microsoft.XMLHTTP</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">);<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}聽</span>
<span style="color: rgb(0, 0, 255);">catch</span>
<span style="color: rgb(0, 0, 0);">聽(e)聽{}<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽}<br /><br />聽聽聽聽聽聽聽聽}<br /><br />聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(</span>
<span style="color: rgb(0, 0, 0);">!</span>
<span style="color: rgb(0, 0, 0);">http_request)聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽alert('Giving聽up聽:(聽Cannot聽create聽an聽XMLHTTP聽instance');<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">return</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 255);">false</span>
<span style="color: rgb(0, 0, 0);">;<br /><br />聽聽聽聽聽聽聽聽}<br /><br />聽聽聽聽聽聽聽聽http_request.onreadystatechange聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽alertContents;<br /><br />聽聽聽聽聽聽聽聽http_request.open('GET',聽url,聽</span>
<span style="color: rgb(0, 0, 255);">true</span>
<span style="color: rgb(0, 0, 0);">);<br /><br />聽聽聽聽聽聽聽聽http_request.send(</span>
<span style="color: rgb(0, 0, 255);">null</span>
<span style="color: rgb(0, 0, 0);">);<br /><br />聽聽聽聽}<br /><br />聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">function</span>
<span style="color: rgb(0, 0, 0);">聽alertContents()聽{<br /><br />聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(http_request.readyState聽</span>
<span style="color: rgb(0, 0, 0);">==</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 0);">4</span>
<span style="color: rgb(0, 0, 0);">)聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽</span>
<span style="color: rgb(0, 0, 255);">if</span>
<span style="color: rgb(0, 0, 0);">聽(http_request.status聽</span>
<span style="color: rgb(0, 0, 0);">==</span>
<span style="color: rgb(0, 0, 0);">聽</span>
<span style="color: rgb(0, 0, 0);">200</span>
<span style="color: rgb(0, 0, 0);">)聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽alert(http_request.responseText);<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽}聽</span>
<span style="color: rgb(0, 0, 255);">else</span>
<span style="color: rgb(0, 0, 0);">聽{<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽alert('There聽was聽a聽problem聽</span>
<span style="color: rgb(0, 0, 255);">with</span>
<span style="color: rgb(0, 0, 0);">聽the聽request.');<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽}<br /><br />聽聽聽聽聽聽聽聽}<br /><br />聽聽聽聽}<br /><br /></span>
<span style="color: rgb(0, 0, 0);"></</span>
<span style="color: rgb(0, 0, 0);">script</span>
<span style="color: rgb(0, 0, 0);">></span>
<span style="color: rgb(0, 0, 0);">
<br />
<br />
</span>
<span style="color: rgb(0, 0, 0);"><</span>
<span style="color: rgb(0, 0, 0);">span<br /><br />聽聽聽聽style</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">cursor:聽pointer;聽text-decoration:聽underline</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">
<br />
<br />聽聽聽聽onclick</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">makeRequest('test.html')</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">></span>
<span style="color: rgb(0, 0, 0);">
<br />
<br />聽聽聽聽聽聽聽聽Make聽a聽request<br /><br /></span>
<span style="color: rgb(0, 0, 0);"></</span>
<span style="color: rgb(0, 0, 0);">span</span>
<span style="color: rgb(0, 0, 0);">></span>
</div>
<o:p>
</o:p>
<p>
<br />
</p>
<p>鍦ㄦ鑼冧緥涓細 <o:p></o:p></p>
<ul type="disc">
<li id="wmqeeuq" class="MsoNormal">棣栧厛浣跨敤鑰呮寜涓嬨€孧ake a request銆?<o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">榪欎箞涓€鏉ュ氨浼氬懠鍙?br />聽聽聽聽 <code>makeRequest()</code> 鍑藉紡錛屼害浼犲叆鍙傛暟鍊?<code>test.html</code> (涔熷氨鏄偅浠?HTML 妗g殑鍚嶇О錛屾斁鍦ㄥ悓鐩綍涓? <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">鎺ョ潃鍙戝嚭 request錛岃€屽悗浼氬皢涓誨鏉冧氦緇?br />聽聽聽聽 <code>onreadystatechange</code> 鎸囧畾鐨?<code>alertContents()</code> 鍑藉紡 <o:p></o:p></li>
<li id="wmqeeuq" class="MsoNormal">
<code>alertContents()</code> 媯€鏌ュ搷搴旀槸鍚︽甯革紝鑰屽悗浠?<code>alert()</code> 灝?<code>test.html</code> 鐨勫唴瀹瑰垪鍑?<o:p></o:p></li>
</ul>
<p>浣犲彲浠?a target="_blank">鐢辨嫻嬭瘯鏈緥</a> (<i><a target="_blank" >http://www.w3clubs.com/mozdev/httprequest_test.html</a></i>)錛屼篃鍙互鍙傝€?a target="_blank">嫻嬭瘯妗f</a> (<i><a target="_blank" >http://www.w3clubs.com/mozdev/test.html</a></i>)銆?br /><o:p></o:p></p>
<h2>絎洓姝?鈥?銆孹 妗f銆嶏紙鍙堢О涓恒€屽鐞?XML 鍝嶅簲鍊箋€嶏級 <o:p></o:p></h2>
<p>鍓嶉潰鐨勪緥瀛愪腑錛屽湪鏀跺埌 HTTP 浼犲洖鍊煎悗鎴戜滑浠ュ璞$殑 <code>reponseText</code> 灞炴€т嬌鐢?<code>test.html</code> 妗f鐨勫唴瀹癸紝鎺ョ潃鏉ヨ瘯璇?<code>responseXML</code> 灞炴€х殑鏂規硶銆?<o:p></o:p></p>
<p>棣栧厛錛屾垜浠緱鍋氫釜鏍煎紡姝g‘鐨?XML 鏂囦歡錛屼互渚跨◢鍚庡彇鐢ㄣ€傛妗e悕鍞?<code>test.xml</code>錛屽唴瀹瑰涓嬶細</p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 255);"><?</span>
<span style="color: rgb(255, 0, 255);">xml聽version="1.0"聽</span>
<span style="color: rgb(0, 0, 255);">?></span>
<span style="color: rgb(0, 0, 0);">
<br />
<br />
</span>
<span style="color: rgb(0, 0, 255);"><</span>
<span style="color: rgb(128, 0, 0);">root</span>
<span style="color: rgb(0, 0, 255);">></span>
<span style="color: rgb(0, 0, 0);">
<br />
<br />聽聽聽聽I'm聽a聽test.<br /><br /></span>
<span style="color: rgb(0, 0, 255);"></</span>
<span style="color: rgb(128, 0, 0);">root</span>
<span style="color: rgb(0, 0, 255);">></span>
</div>
<o:p>
</o:p>
<p>
<br />
</p>
<p>鍦ㄧ▼搴忎腑錛屾垜浠彨鐢ㄦ。妗堢殑鍦版柟鍙』鐣ヤ簨淇敼濡備笅錛?<o:p></o:p></p>
<pre>...<o:p></o:p></pre>
<pre>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 0);">onclick</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">"</span>
<span style="color: rgb(0, 0, 0);">makeRequest('test.xml')</span>
<span style="color: rgb(0, 0, 0);">"</span>
</div>
<o:p>
</o:p>
</pre>
<pre>...<o:p></o:p></pre>
<p>鎺ョ潃鍦?<code>alertContents()</code> 涓紝鎴戜滑蹇呴』灝?<code>alert(http_request.responseText);</code> 鏀規垚榪欐牱錛?/p>
<p>
<br />
<o:p>
</o:p>
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<span style="color: rgb(0, 0, 255);">var</span>
<span style="color: rgb(0, 0, 0);">聽xmldoc聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽http_request.responseXML;<br /><br /></span>
<span style="color: rgb(0, 0, 255);">var</span>
<span style="color: rgb(0, 0, 0);">聽root_node聽</span>
<span style="color: rgb(0, 0, 0);">=</span>
<span style="color: rgb(0, 0, 0);">聽xmldoc.getElementsByTagName('root').item(</span>
<span style="color: rgb(0, 0, 0);">0</span>
<span style="color: rgb(0, 0, 0);">);<br /><br />alert(root_node.firstChild.data);</span>
</div>
<br />
<o:p>
</o:p>
<br />榪欐牱涓€鏉ユ垜浠究鍙彇寰?<code>responseXML</code> 鎵€浼犲洖鐨?<code>XMLDocument</code> 瀵硅薄錛岃€屽悗浠?DOM 鐩稿叧鐨勬柟娉曞彇鐢?br />XML 鏂囦歡鍐呭銆備綘鍙互鍙傝€?<a target="_blank"><code>test.xml</code> 鐨勫師濮嬬爜</a> (<i><a target="_blank" >http://www.w3clubs.com/mozdev/test.xml</a></i>)<br />浠ュ強淇敼榪囧悗鐨?a target="_blank">嫻嬭瘯紼嬪簭</a> (<i><a target="_blank" >http://www.w3clubs.com/mozdev/httprequest_test_xml.html</a></i>)銆?img src ="http://www.aygfsteel.com/paulwong/aggbug/44684.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2006-05-05 22:21 <a href="http://www.aygfsteel.com/paulwong/articles/44684.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer>
<div class="friendship-link">
<a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a>
</div>
</footer>
主站蜘蛛池模板:
<a href="http://" target="_blank">南京市</a>|
<a href="http://" target="_blank">钦州市</a>|
<a href="http://" target="_blank">麻江县</a>|
<a href="http://" target="_blank">华容县</a>|
<a href="http://" target="_blank">雷波县</a>|
<a href="http://" target="_blank">桐乡市</a>|
<a href="http://" target="_blank">凉城县</a>|
<a href="http://" target="_blank">台湾省</a>|
<a href="http://" target="_blank">成武县</a>|
<a href="http://" target="_blank">微博</a>|
<a href="http://" target="_blank">余干县</a>|
<a href="http://" target="_blank">三河市</a>|
<a href="http://" target="_blank">汝城县</a>|
<a href="http://" target="_blank">教育</a>|
<a href="http://" target="_blank">兴山县</a>|
<a href="http://" target="_blank">江油市</a>|
<a href="http://" target="_blank">霍州市</a>|
<a href="http://" target="_blank">泗水县</a>|
<a href="http://" target="_blank">金川县</a>|
<a href="http://" target="_blank">渝北区</a>|
<a href="http://" target="_blank">张北县</a>|
<a href="http://" target="_blank">西盟</a>|
<a href="http://" target="_blank">都兰县</a>|
<a href="http://" target="_blank">水富县</a>|
<a href="http://" target="_blank">西充县</a>|
<a href="http://" target="_blank">尉犁县</a>|
<a href="http://" target="_blank">连山</a>|
<a href="http://" target="_blank">阿拉尔市</a>|
<a href="http://" target="_blank">禹城市</a>|
<a href="http://" target="_blank">浦东新区</a>|
<a href="http://" target="_blank">库伦旗</a>|
<a href="http://" target="_blank">西贡区</a>|
<a href="http://" target="_blank">屏东市</a>|
<a href="http://" target="_blank">巴塘县</a>|
<a href="http://" target="_blank">舟山市</a>|
<a href="http://" target="_blank">井研县</a>|
<a href="http://" target="_blank">台前县</a>|
<a href="http://" target="_blank">会理县</a>|
<a href="http://" target="_blank">锡林郭勒盟</a>|
<a href="http://" target="_blank">如东县</a>|
<a href="http://" target="_blank">宁夏</a>|
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>
</body>