aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/xmlhttprequest/responsetext
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/xmlhttprequest/responsetext
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/xmlhttprequest/responsetext')
-rw-r--r--files/zh-cn/web/api/xmlhttprequest/responsetext/index.html114
1 files changed, 114 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/xmlhttprequest/responsetext/index.html b/files/zh-cn/web/api/xmlhttprequest/responsetext/index.html
new file mode 100644
index 0000000000..5b6708acd4
--- /dev/null
+++ b/files/zh-cn/web/api/xmlhttprequest/responsetext/index.html
@@ -0,0 +1,114 @@
+---
+title: XMLHttpRequest.responseText
+slug: Web/API/XMLHttpRequest/responseText
+tags:
+ - XMLHttpRequest.responseText
+translation_of: Web/API/XMLHttpRequest/responseText
+---
+<div>{{draft}}</div>
+
+<div>{{APIRef('XMLHttpRequest')}}</div>
+
+<p><strong>XMLHttpRequest.responseText </strong>在一个请求被发送后,从服务器端返回文本。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre>var resultText = XMLHttpRequest.responseText;</pre>
+
+<h3 id="取值">取值</h3>
+
+<p>{{domxref("DOMString")}} 是<code>XMLHttpRequest</code> 返回的纯文本的值。当{{domxref("DOMString")}} 为<code>null</code>时,表示请求失败了。当{{domxref("DOMString")}} 为""时,表示这个请求还没有被{{domxref("XMLHttpRequest.send", "send()")}}</p>
+
+<p>当处理一个异步request的时候,尽管当前请求并没有结束,<code>responseText</code>的返回值是当前从后端收到的内容。</p>
+
+<p>当请求状态{{domxref("XMLHttpRequest.readyState", "readyState")}}变为{{domxref("XMLHttpRequest.DONE", "XMLHttpRequest.DONE")}} (<code>4</code>),且{{domxref("XMLHttpRequest.status", "status")}}值为200(<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">"OK"</span></font>)时,<code>responseText</code>是全部后端的返回数据</p>
+
+<h2 id="例子">例子</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="格式">格式</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">格式</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('XMLHttpRequest', '#the-responsetext-attribute')}}</td>
+ <td>{{Spec2('XMLHttpRequest')}}</td>
+ <td>WHATWG living standard</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}<sup>[1]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] 在IE10前的版本请求完成时, XMLHttpRequest.responseText 的值为只读。</p>