OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Utility class for making XHRs more pleasant. | 7 * Utility class for making XHRs more pleasant. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 this.url = xhr.responseURL; | 287 this.url = xhr.responseURL; |
288 | 288 |
289 /** @private {string} */ | 289 /** @private {string} */ |
290 this.text_ = xhr.responseText || ''; | 290 this.text_ = xhr.responseText || ''; |
291 | 291 |
292 /** @private {*|undefined} */ | 292 /** @private {*|undefined} */ |
293 this.json_ = undefined; | 293 this.json_ = undefined; |
294 }; | 294 }; |
295 | 295 |
296 /** | 296 /** |
| 297 * @return {boolean} True if the response code is outside the 200-299 |
| 298 * range (i.e. success as defined by the HTTP protocol). |
| 299 */ |
| 300 remoting.Xhr.Response.prototype.isError = function() { |
| 301 return this.status < 200 || this.status >= 300; |
| 302 }; |
| 303 |
| 304 /** |
297 * @return {string} The text content of the response. | 305 * @return {string} The text content of the response. |
298 */ | 306 */ |
299 remoting.Xhr.Response.prototype.getText = function() { | 307 remoting.Xhr.Response.prototype.getText = function() { |
300 return this.text_; | 308 return this.text_; |
301 }; | 309 }; |
302 | 310 |
303 /** | 311 /** |
304 * Get the JSON content of the response. Requires acceptJson to have | 312 * Get the JSON content of the response. Requires acceptJson to have |
305 * been true in the request. | 313 * been true in the request. |
306 * @return {*} The parsed JSON content of the response. | 314 * @return {*} The parsed JSON content of the response. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 var paramArray = []; | 353 var paramArray = []; |
346 for (var key in paramHash) { | 354 for (var key in paramHash) { |
347 paramArray.push(encodeURIComponent(key) + | 355 paramArray.push(encodeURIComponent(key) + |
348 '=' + encodeURIComponent(paramHash[key])); | 356 '=' + encodeURIComponent(paramHash[key])); |
349 } | 357 } |
350 if (paramArray.length > 0) { | 358 if (paramArray.length > 0) { |
351 return paramArray.join('&'); | 359 return paramArray.join('&'); |
352 } | 360 } |
353 return ''; | 361 return ''; |
354 }; | 362 }; |
OLD | NEW |