--- 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 --- <div>{{draft}}</div> <div>{{APIRef('XMLHttpRequest')}}</div> <p><span class="seoSummary">{{domxref("XMLHttpRequest")}} の <strong><code>responseText</code></strong> プロパティは読み取り専用で、送信されたリクエストに続いてサーバーから受け取ったテキストを返します。</span></p> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox">var <var>resultText</var> = <var>XMLHttpRequest</var>.responseText;</pre> <h3 id="Value" name="Value">値</h3> <p>{{domxref("DOMString")}} で、 <code>XMLHttpRequest</code> を使用して受信したテキストデータ、またはリクエストが失敗したときは <code>null</code>、またはリクエストがまだ {{domxref("XMLHttpRequest.send", "send()")}} の呼び出しによって送信されていない場合は <code>""</code>。</p> <p>非同期リクエストを処理している間、 <code>responseText</code> の値は、データが完全に受信できておらず不完全であっても、常にサーバーから受信した現在のコンテンツを持ちます。</p> <p>{{domxref("XMLHttpRequest.readyState", "readyState")}} の値が {{domxref("XMLHttpRequest.DONE", "XMLHttpRequest.DONE")}} (<code>4</code>) になり、 {{domxref("XMLHttpRequest.status", "status")}} の値が 200 (<code>"OK"</code>) になった場合、コンテンツ全体が受信されたことが分かります。</p> <h3 id="Exceptions" name="Exceptions">例外</h3> <dl> <dt><code>InvalidStateError</code></dt> <dd>{{domxref("XMLHttpRequest.responseType")}} が空文字列または <code>"text"</code> のどちらにも設定されていません。 <code>responseText</code> プロパティはテキストコンテンツのみで有効なので、他の値はエラーの状態です。</dd> </dl> <h2 id="Example" name="Example">例</h2> <pre class="brush: js">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);</pre> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> <th scope="col">備考</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('XMLHttpRequest', '#the-responsetext-attribute')}}</td> <td>{{Spec2('XMLHttpRequest')}}</td> <td>WHATWG living standard</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <p>{{Compat("api.XMLHttpRequest.responseText")}}</p>