为了账号安全,请及时绑定邮箱和手机立即绑定

我用ajax调用文本内容,但是在浏览其中就是没法显示,请大神们帮帮忙!!!谢谢了!!

我用ajax调用文本内容,但是在浏览其中就是没法显示,请大神们帮帮忙!!!谢谢了!!

闯货的红灯3128172 2016-12-08 13:56:52
<!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内容:你好!
查看完整描述

3 回答

?
Elem

TA贡献4条经验 获得超2个赞

换个浏览器。非http请求,有的浏览器不支持

查看完整回答
反对 回复 2016-12-10
?
杰杰就是我

TA贡献32条经验 获得超24个赞

我运行的结果为 弹出 Function Done , 然后页面出现 你好!  不知道你想表达的是什么错误 

查看完整回答
反对 回复 2016-12-09
  • 3 回答
  • 0 关注
  • 1396 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信