XMLHttpRequest getResponseHeader() メソッド
XMLHttpRequest オブジェクト
定義と用法
getResponseHeader() メソッドは、XMLHttpRequest オブジェクトの指定のレスポンス・ヘッダを含む文字列を取得します。
レスポンス・ヘッダには、長さ、サーバ・タイプ、コンテンツタイプ、更新日等のファイル情報が含まれています。
構文
xmlHttp.getResponseHeader(header) |
パラメータ |
説明 |
name |
取得するヘッダ名を指定する文字列。
getAllResponseHeaders() メソッドを使用すれば、指定の文書に対して使用できるヘッダ名を探すことができます。 |
例
次のコードは、id="headers" を持つ HTML 要素の "Content-Length" ヘッダを出力します:
例
<html>
<body>
<span id="header"></span>
<script type="text/javascript">
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for Firefox, Mozilla, IE7, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4)
{
x=xmlhttp.getResponseHeader("Content-Length");
document.getElementById("header").innerHTML=x;
}
}
xmlhttp.open("GET", "note.xml", true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
</script>
</body>
</html>
|
出力:
試してください »
|
XMLHttpRequest オブジェクト
|