// http://localhost/ajax/head.html
<html>
<head>
<title>Reading header information</title>
<script language = "javascript">
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function getData(dataSource, divID)
{
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("HEAD", dataSource);
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.getAllResponseHeaders();
}
}
XMLHttpRequestObject.send(null);
}
}
</script>
</head>
<body>
<H1>Reading header information</H1>
<form>
<input type = "button" value = "Display Head Information"
onclick = "getData('data.txt', 'targetDiv')">
</form>
<div id="targetDiv">
<p>The fetched data will go here.</p>
</div>
</body>
</html>
//data.txt file
This text was fetched using Ajax.
0 comments:
Post a Comment