<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>repeat</title>
</head>
<body>
<p>it seemed that the first Ajax should be vary easy!</p>
<p id="recieved"></p>
<input type="button" value="提交" onclick="getNewContent();">
<script>
var request = false;
try{
request = new XMLHttpRequest();
}catch(trymicrosoft){
try{
request = new ActiveXObject("Msxml2.XMLHTTP.6.0");
}catch(earlier){
try{
request = new ActiveXObject("Msxml2.XMLHTTP.3.0");
}catch(moreearlier){
try{
request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(failed){
request = false;
}
}
}
}
if (!request) alert("no Ajax here");
function getNewContent(){
if (request) {
request.open("GET","target.xml",true);
request.onreadystatechange = hhh;
request.send(null);
}
}
function hhh() {
if (request.readyState == 4) {
//alert(request.status);
console.log(request.status);
var recievedText = document.getElementById('recieved');
var responceT =document.createTextNode(request.responseText);
recievedText.appendChild(responceT);
}
}
</script>
</body>
</html>
console.log(request.status) lauten wie folgt:
firefox:
Chrom:
Entschuldigung, warum gibt es zwei verschiedene Status? Wird dieser Unterschied nicht auftreten, wenn wir einen Server im Web verwenden?
此博客有详细的介绍
http://blog.csdn.net/iaiti/ar...
ajax本来就是为了在服务器用。在本地应该就不可以用。具体的东西。你可以用chrome打开network 和 FF打开网络查看