ホーム HTML CSS XML JAVASCRIPT   PHP SQL MORE...   リファレンス 事例集    

XMLHttpRequest getAllResponseHeaders() メソッド


XMLHttpRequest Object Reference XMLHttpRequest オブジェクト

定義と用法

getAllResponseHeaders() メソッドは、XMLHttpRequest オブジェクトの全てのレスポンス・ヘッダを含む文字列を取得します。

レスポンス・ヘッダには、長さ、サーバ・タイプ、コンテンツタイプ、更新日等のファイル情報が含まれています。

構文

xmlHttp.getAllResponseHeaders()


次のコードは、id="headers" を持つ HTML 要素の全てのレスポンス・ヘッダを出力します:

<html>
<body>

<span id="headers"></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.getAllResponseHeaders();
      document.getElementById("headers").innerHTML=x;
      }
    }
  xmlhttp.open("GET", "note.xml", true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
</script>
</body>
</html>

出力は次のようになります (ブラウザに依存):

Content-Length: 195 Content-Type: text/xml
ETag: "b34ba3751251c81:4cd" X-Powered-By: ASP.NET
MicrosoftOfficeWebServer: 5.0_Pub
Last-Modified: Mon, 07 Jan 2008 09:48:30 GMT

試してください »

XMLHttpRequest Object Reference XMLHttpRequest オブジェクト