<html><!DOCTYPE html><html><head><script>functionloadXMLDoc(url){var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById('A1').innerHTML=xmlhttp.status;
document.getElementById('A2').innerHTML=xmlhttp.statusText;
document.getElementById('A3').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script></head><body><h2>Retrieve data from XML file</h2><p><b>Status:</b><spanid="A1"></span></p><p><b>Status text:</b><spanid="A2"></span></p><p><b>Response:</b><spanid="A3"></span></p><buttononclick="loadXMLDoc('note.xml')">Get XML data</button></body></html>
用AJAX进行一次 HEAD 请求
检索资源(文件)的头信息。
<html><!DOCTYPE html><html><head><script>functionloadXMLDoc(url){var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById('p1').innerHTML=xmlhttp.getAllResponseHeaders();
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script></head><body><pid="p1">The getAllResponseHeaders() function returns the header information of a resource, like length, server-type, content-type, last-modified, etc.</p><buttononclick="loadXMLDoc('/try/ajax/ajax_info.txt')">Get header information</button></body></html>
用AJAX进行一次指定的 HEAD 请求
检索资源(文件)的指定头信息。
<html><!DOCTYPE html><html><head><script>functionloadXMLDoc(url){var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById('p1').innerHTML="Last modified: " + xmlhttp.getResponseHeader('Last-Modified');
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script></head><body><pid="p1">The getResponseHeader() function is used to return specific header information from a resource, like length, server-type, content-type, last-modified, etc.</p><buttononclick="loadXMLDoc('/try/ajax/ajax_info.txt')">Get "Last-Modified" information</button></body></html>