<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Ajax</title></head><body><div id="new" ></div><script>function getHTTPObject(){ if(typeof XMLHttpRequest=="undefined") ?XMLHttpRequest=function(){ ?try{return new ActiveXObject("Msxml2.XMLHTTP.6.0");} ?catch(e){} ?try{return new ActiveXObject("Msxml2.XMLHTTP.3.0");} ?catch(e){} ?try{return new ActiveXObjec("Msxml2.XMLHTTP");} ?catch(e){} ?try{return new ActiveXObject("Microsoft.XMLHTTP");} ?catch(e){} ?return false; ?} ?return new XMLHttpRequest(); } function getNewContent(){ var request=getHTTPObject(); if(request){ request.open("GET","example.txt",true); request.onreadystatechange=function(){ if(request.readyState==4){ var para= document.createElement("p"); var txt=document.createTextNode(request.responseText); para.appendChild(txt); document.getElementById('new').appendChild(para); } }; request.send(null); }else{ alert('Sorry,your browser dont\'t support XMLhttpRequest'); } alert("Function Done") } function addLoadEvent(func){ var onload=window.onload; if(typeof (window.onload) !='function'){ window.onload=func; }else{ window.onload=function(){ onload(); func(); } } }addLoadEvent(getNewContent);addLoadEvent(getHTTPObject);</script></body></html>文本和這個html在一個文件夾下,txt內(nèi)容:你好!
我用ajax調(diào)用文本內(nèi)容,但是在瀏覽其中就是沒法顯示,請大神們幫幫忙?。?!謝謝了!!
闖貨的紅燈3128172
2016-12-08 13:56:52