火狐正常
在火狐中正常,在谷歌和360会报错,也没有改变内容,怎么解决
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> ajax读取txt文本内容</title>
<script type="text/javascript">
function startRequest(){
var xmlHttp;
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
xmlHttp.onreadystatechange=function(){
if (xmlHttp.readyState==4 && xmlHttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","test.txt",true);
xmlHttp.send();
}
</script>
</head>
<body>
<div id="myDiv"></div>
<button type="button" onclick="startRequest()">修改内容</button>
</body>
</html>
大部分浏览器由于安全策略不允许读取本地文件,请在web服务器上运行页面