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/responsetext/index.html | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 files/ja/web/api/xmlhttprequest/responsetext/index.html (limited to 'files/ja/web/api/xmlhttprequest/responsetext/index.html') diff --git a/files/ja/web/api/xmlhttprequest/responsetext/index.html b/files/ja/web/api/xmlhttprequest/responsetext/index.html new file mode 100644 index 0000000000..35f246a68f --- /dev/null +++ b/files/ja/web/api/xmlhttprequest/responsetext/index.html @@ -0,0 +1,83 @@ +--- +title: XMLHttpRequest.responseText +slug: Web/API/XMLHttpRequest/responseText +tags: + - API + - Fetching Text + - Loading Text + - Property + - Read-only + - Reference + - XMLHttpRequest + - responseText + - プロパティ +translation_of: Web/API/XMLHttpRequest/responseText +--- +
{{draft}}
+ +
{{APIRef('XMLHttpRequest')}}
+ +

{{domxref("XMLHttpRequest")}} の responseText プロパティは読み取り専用で、送信されたリクエストに続いてサーバーから受け取ったテキストを返します。

+ +

構文

+ +
var resultText = XMLHttpRequest.responseText;
+ +

+ +

{{domxref("DOMString")}} で、 XMLHttpRequest を使用して受信したテキストデータ、またはリクエストが失敗したときは null、またはリクエストがまだ {{domxref("XMLHttpRequest.send", "send()")}} の呼び出しによって送信されていない場合は ""

+ +

非同期リクエストを処理している間、 responseText の値は、データが完全に受信できておらず不完全であっても、常にサーバーから受信した現在のコンテンツを持ちます。

+ +

{{domxref("XMLHttpRequest.readyState", "readyState")}} の値が {{domxref("XMLHttpRequest.DONE", "XMLHttpRequest.DONE")}} (4) になり、 {{domxref("XMLHttpRequest.status", "status")}} の値が 200 ("OK") になった場合、コンテンツ全体が受信されたことが分かります。

+ +

例外

+ +
+
InvalidStateError
+
{{domxref("XMLHttpRequest.responseType")}} が空文字列または "text" のどちらにも設定されていません。 responseText プロパティはテキストコンテンツのみで有効なので、他の値はエラーの状態です。
+
+ +

+ +
var xhr = new XMLHttpRequest();
+xhr.open('GET', '/server', true);
+
+// If specified, responseType must be empty string or "text"
+xhr.responseType = 'text';
+
+xhr.onload = function () {
+    if (xhr.readyState === xhr.DONE) {
+        if (xhr.status === 200) {
+            console.log(xhr.response);
+            console.log(xhr.responseText);
+        }
+    }
+};
+
+xhr.send(null);
+ +

仕様書

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

ブラウザーの互換性

+ + + +

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

-- cgit v1.2.3-54-g00ecf