AJAX技术实现局部刷新,如遇浏览器报错,请看:Cross origin requests are only supported for protocol schemes: http, data, chrome
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
console.log("ready");
"文件ajax_info.txt在本地,不需要等待请求及创建状态码"
"if (xmlhttp.readyState==4 && xmlhttp.status==200)"
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
console.log("before changed");
xmlhttp.open("GET", "ajax_info.txt",true);
console.log("open file");
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>这里将被修改</h2></div>
<button type="button" onclick="loadXMLDoc()">修改</button>
</body>
</html>

1353

被折叠的 条评论
为什么被折叠?



