Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
The Google Closure Library is a collection of JavaScript code
designed for use with the Google Closure JavaScript Compiler.
This non-official distribution was prepared by the ClojureScript
team at http://clojure.org/
// Copyright 2011 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Offered as an alternative to XhrIo as a way for making requests
* via XMLHttpRequest. Instead of mirroring the XHR interface and exposing
* events, results are used as a way to pass a "promise" of the response to
* interested parties.
*
*/
goog.provide('goog.labs.net.xhr');
goog.provide('goog.labs.net.xhr.Error');
goog.provide('goog.labs.net.xhr.HttpError');
goog.provide('goog.labs.net.xhr.Options');
goog.provide('goog.labs.net.xhr.PostData');
goog.provide('goog.labs.net.xhr.ResponseType');
goog.provide('goog.labs.net.xhr.TimeoutError');
goog.require('goog.Promise');
goog.require('goog.asserts');
goog.require('goog.debug.Error');
goog.require('goog.json');
goog.require('goog.net.HttpStatus');
goog.require('goog.net.XmlHttp');
goog.require('goog.string');
goog.require('goog.uri.utils');
goog.require('goog.userAgent');
goog.scope(function() {
var userAgent = goog.userAgent;
var xhr = goog.labs.net.xhr;
var HttpStatus = goog.net.HttpStatus;
/**
* Configuration options for an XMLHttpRequest.
* - headers: map of header key/value pairs.
* - timeoutMs: number of milliseconds after which the request will be timed
* out by the client. Default is to allow the browser to handle timeouts.
* - withCredentials: whether user credentials are to be included in a
* cross-origin request. See:
* http://www.w3.org/TR/XMLHttpRequest/#the-withcredentials-attribute
* - mimeType: allows the caller to override the content-type and charset for
* the request. See:
* http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-overridemimetype
* - responseType: may be set to change the response type to an arraybuffer or
* blob for downloading binary data. See:
* http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-responsetype]
* - xmlHttpFactory: allows the caller to override the factory used to create
* XMLHttpRequest objects.
* - xssiPrefix: Prefix used for protecting against XSSI attacks, which should
* be removed before parsing the response as JSON.
*
* @typedef {{
* headers: (Object|undefined),
* mimeType: (string|undefined),
* responseType: (xhr.ResponseType|undefined),
* timeoutMs: (number|undefined),
* withCredentials: (boolean|undefined),
* xmlHttpFactory: (goog.net.XmlHttpFactory|undefined),
* xssiPrefix: (string|undefined)
* }}
*/
xhr.Options;
/**
* Defines the types that are allowed as post data.
* @typedef {(ArrayBuffer|Blob|Document|FormData|null|string|undefined)}
*/
xhr.PostData;
/**
* The Content-Type HTTP header name.
* @type {string}
*/
xhr.CONTENT_TYPE_HEADER = 'Content-Type';
/**
* The Content-Type HTTP header value for a url-encoded form.
* @type {string}
*/
xhr.FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded;charset=utf-8';
/**
* Supported data types for the responseType field.
* See: http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-response
* @enum {string}
*/
xhr.ResponseType = {
ARRAYBUFFER: 'arraybuffer',
BLOB: 'blob',
DOCUMENT: 'document',
JSON: 'json',
TEXT: 'text'
};
/**
* Sends a get request, returning a promise that will be resolved
* with the response text once the request completes.
*
* @param {string} url The URL to request.
* @param {xhr.Options=} opt_options Configuration options for the request.
* @return {!goog.Promise} A promise that will be resolved with the
* response text once the request completes.
*/
xhr.get = function(url, opt_options) {
return xhr.send('GET', url, null, opt_options).then(function(request) {
return request.responseText;
});
};
/**
* Sends a post request, returning a promise that will be resolved
* with the response text once the request completes.
*
* @param {string} url The URL to request.
* @param {xhr.PostData} data The body of the post request.
* @param {xhr.Options=} opt_options Configuration options for the request.
* @return {!goog.Promise} A promise that will be resolved with the
* response text once the request completes.
*/
xhr.post = function(url, data, opt_options) {
return xhr.send('POST', url, data, opt_options).then(function(request) {
return request.responseText;
});
};
/**
* Sends a get request, returning a promise that will be resolved with
* the parsed response text once the request completes.
*
* @param {string} url The URL to request.
* @param {xhr.Options=} opt_options Configuration options for the request.
* @return {!goog.Promise