日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ajax html例子,AJAX实例

發(fā)布時(shí)間:2025/3/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajax html例子,AJAX实例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

AJAX實(shí)例

實(shí)例一:一個(gè)簡(jiǎn)單的AJAX實(shí)例

創(chuàng)建一個(gè)簡(jiǎn)單的XMLHttpRequest,從一個(gè)TXT文件中返回?cái)?shù)據(jù)

實(shí)例

function?loadXMLDoc()

{

var?xmlhttp;

if?(window.XMLHttpRequest)

{

//??IE7+,?Firefox,?Chrome,?Opera,?Safari?瀏覽器執(zhí)行代碼

xmlhttp=new?XMLHttpRequest();

}

else

{

//?IE6,?IE5?瀏覽器執(zhí)行代碼

xmlhttp=new?ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function()

{

if?(xmlhttp.readyState==4?&&?xmlhttp.status==200)

{

document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

}

}

xmlhttp.open("GET","ajax_info.txt",true);

xmlhttp.send();

}

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

效果圖:

實(shí)例二:通過 XML HTTP 進(jìn)行一次指定的 HEAD 請(qǐng)求

實(shí)例

function?loadXMLDoc(url)

{

var?xmlhttp;

if?(window.XMLHttpRequest)

{//?code?for?IE7+,?Firefox,?Chrome,?Opera,?Safari

xmlhttp=new?XMLHttpRequest();

}

else

{//?code?for?IE6,?IE5

xmlhttp=new?ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function()

{

if?(xmlhttp.readyState==4?&&?xmlhttp.status==200)

{

document.getElementById('p1').innerHTML="Last?modified:?"?+?xmlhttp.getResponseHeader('Last-Modified');

}

}

xmlhttp.open("GET",url,true);

xmlhttp.send();

}

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

效果圖:

實(shí)例三:把 XML 文件顯示為 HTML 表格

實(shí)例

function?onResponse()

{

if(xmlhttp.readyState!=4)?return;

if(xmlhttp.status!=200)

{

alert("Problem?retrieving?XML?data");

return;

}

txt="

x=xmlhttp.responseXML.documentElement.getElementsByTagName("CD");

for?(i=0;i

{

txt=txt?+?"

";

xx=x[i].getElementsByTagName("TITLE");

{

try

{

txt=txt?+?"

"?+?xx[0].firstChild.nodeValue?+?"";

}

catch?(er)

{

txt=txt?+?"

?";

}

}

xx=x[i].getElementsByTagName("ARTIST");

{

try

{

txt=txt?+?"

"?+?xx[0].firstChild.nodeValue?+?"";

}

catch?(er)

{

txt=txt?+?"

?";

}

}

txt=txt?+?"

";

}

txt=txt?+?"

";

document.getElementById('copy').innerHTML=txt;

}

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

效果圖:

總結(jié)

以上是生活随笔為你收集整理的ajax html例子,AJAX实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。