From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/xmlhttprequest/responsexml/index.html | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 files/ja/web/api/xmlhttprequest/responsexml/index.html (limited to 'files/ja/web/api/xmlhttprequest/responsexml') diff --git a/files/ja/web/api/xmlhttprequest/responsexml/index.html b/files/ja/web/api/xmlhttprequest/responsexml/index.html new file mode 100644 index 0000000000..f5f989624a --- /dev/null +++ b/files/ja/web/api/xmlhttprequest/responsexml/index.html @@ -0,0 +1,109 @@ +--- +title: XMLHttpRequest.responseXML +slug: Web/API/XMLHttpRequest/responseXML +tags: + - AJAX + - API + - Fetching XML + - Loading XML + - Property + - Read-only + - Reading XML + - Reference + - Transfer + - XML + - XMLHttpRequest + - download + - responseXML + - upload + - アップロード + - ダウンロード + - プロパティ + - 変換 + - 読み取り専用 +translation_of: Web/API/XMLHttpRequest/responseXML +--- +
{{APIRef('XMLHttpRequest')}}
+ +

XMLHttpRequest.responseXML は読み取り専用のプロパティで、リクエストによって受け取った HTML または XML を含む {{domxref("Document")}}、またはリクエストが成功しなかった場合、まだ送信されていない場合、データが XML または HTML として解釈できない場合は null を返します。

+ +
+

メモ: responseXML という名前はこのプロパティの歴史の遺物です。これは HTML および XML の両方で動作します。

+
+ +

ふつう、レスポンスは "text/xml" として解釈されます。 {{domxref("XMLHttpRequest.responseType", "responseType")}} が "document" に設定され、リクエストが非同期に行われた場合、レスポンスは代わりに "text/html" として解釈されます。他の型のデータでは、 data: の URL の場合と同様、 responseXMLnull になります。

+ +

サーバーが {{HTTPHeader("Content-Type")}} を "text/xml" とも "application/xml" とも指定しなかった場合、 {{domxref("XMLHttpRequest.overrideMimeType()")}} を使用して強制的に XML として解釈させることができます。

+ +

このプロパティはワーカーでは使用できません。

+ +

構文

+ +
var data = XMLHttpRequest.responseXML;
+
+ +

+ +

{{domxref("XMLHttpRequest")}} を用いて受け取った XML または HTML を解釈した {{domxref("Document")}}、またはデータを受け取っていなかったり、データが XML/HTML でな買ったりした場合は null

+ +

例外

+ +
+
InvalidStateError
+
{{domxref("XMLHttpRequest.responseType", "responseType")}} が "document" でも空文字列でもない。
+
+ +

+ +
var xhr = new XMLHttpRequest;
+xhr.open('GET', '/server');
+
+// responseType を指定する場合は、空文字列または "document" でなければならない
+xhr.responseType = 'document';
+
+// レスポンスを XML として解釈するよう強制する
+xhr.overrideMimeType('text/xml');
+
+xhr.onload = function () {
+  if (xhr.readyState === xhr.DONE && xhr.status === 200) {
+    console.log(xhr.response, xhr.responseXML);
+  }
+};
+
+xhr.send();
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('XMLHttpRequest', '#the-responsexml-attribute', 'responseXML')}}{{Spec2('XMLHttpRequest')}}WHATWG living standard
+ +

ブラウザーの対応

+ + + +

{{Compat("api.XMLHttpRequest.responseXML")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf