取得するデータのヘッダーを全て読み込む

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<script type="text/javascript"><!--
function getAllHeader() {
xmlhttp = createXMLHttpRequest();
if (xmlhttp) {
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
resHeader = xmlhttp.getAllResponseHeaders();
document.getElementById("result").value = resHeader;
}
}
xmlhttp.open("get", "sample.xml", true);
xmlhttp.send(null);
}
}
// XMLHttpオブジェクト作成
function createXMLHttpRequest()
{
var XMLhttpObject = null;
try{
XMLhttpObject = new XMLHttpRequest();
}catch(e){
try{
XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
return null;
}
}
}
return XMLhttpObject;
}
// --></script>
</head>
<body>
<form>
<input type="button" value="すべてのヘッダーを読み込む" onClick="getAllHeader()"><br>
<textarea id="result" rows="20" cols="60"></textarea>
</form>
</body>
</html>
・サンプルを実行する
Ajax逆引きクイックリファレンス 説明などは本書を参考にしてください。