<!DOCTYPE html>
<html>
<head>
<title>test_ajax</title>
<script type="text/javascript">
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>use AJAX to modify this text</h2></div>
<button type="button" onclick="loadXMLDoc()">modify</button>
</body>
</html>
正在学习,感谢~
xmlhttp.open("GET","info.txt",true);第二个参数不就是请求当前目录下的info.txt
xmlhttp.responseText;//这个就是得到返回的文本内容。
原生html不支持,用ie浏览器并且支持activex的话,可以用fso读取本地文件
http://blog.csdn.net/zaifendou/article/details/5733285
你这代码的漂移性,接受状态的时候还没调用请求,我不信你的代码能从下至上执行。