The goog.net.XhrIo Class

goog.net.XhrIo
> goog.events.EventTarget
> goog.Disposable

goog.net.XhrIo(opt_xmlHttpFactory)

Basic class for handling XMLHttpRequests.

opt_xmlHttpFactory {goog.net.XmlHttpFactory=}
Factory to use when creating XMLHttpRequest objects.

.CONTENT_TYPE_HEADER {string}

The Content-Type HTTP header name

.FORM_CONTENT_TYPE {string}

The Content-Type HTTP header value for a url-encoded form

.HTTP_SCHEME_PATTERN {!RegExp}

The pattern matching the 'http' and 'https' URI schemes

The goog.net.XhrIo.ResponseType Enum

Response types that may be requested for XMLHttpRequests. … more

.abort(opt_failureCode)

Abort the current XMLHttpRequest

opt_failureCode {goog.net.ErrorCode=}
Optional error code to use - defaults to ABORT.

.addEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched. Supported for legacy but use goog.events.listen(src, type, handler) instead.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.cleanup()

Disposes all non-disposed instances of goog.net.XhrIo created by {@link goog.net.XhrIo.send}. {@link goog.net.XhrIo.send} cleans up the goog.net.XhrIo instance it creates when the request completes or fails. However, if the request never completes, then the goog.net.XhrIo is not disposed. This can occur if the window is unloaded before the request completes. We could have {@link goog.net.XhrIo.send} return the goog.net.XhrIo it creates and make the client of {@link goog.net.XhrIo.send} be responsible for disposing it in this case. However, this makes things significantly more complicated for the client, and the whole point of {@link goog.net.XhrIo.send} is that it's simple and easy to use. Clients of {@link goog.net.XhrIo.send} should call {@link goog.net.XhrIo.cleanup} when doing final cleanup on window unload.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispatchEvent(e)

Inherited from goog.events.EventTarget .

Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.

e {string|Object|goog.events.Event}
Event object.
returns {boolean}
If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.getAllResponseHeaders()

Gets the text of all the headers in the response. Will only return correct result when called from the context of a callback and the request has completed.

returns {string}
The value of the response headers or empty string.

.getLastError()

Get the last error message

returns {string}
Last error message.

.getLastErrorCode()

Get the last error message

returns {goog.net.ErrorCode}
Last error code.

.getLastUri()

Get the last Uri that was requested

returns {string}
Last Uri.

.getParentEventTarget()

Inherited from goog.events.EventTarget .

Returns the parent of this event target to use for bubbling.

returns {goog.events.EventTarget}
The parent EventTarget or null if there is no parent.

.getReadyState()

Get the readystate from the Xhr object Will only return correct result when called from the context of a callback

returns {goog.net.XmlHttp.ReadyState}
goog.net.XmlHttp.ReadyState.*.

.getResponse()

Get the response as the type specificed by {@link #setResponseType}. At time of writing, this is only directly supported in very recent versions of WebKit (10.0.612.1 dev and later). If the field is not supported directly, we will try to emulate it. Emulating the response means following the rules laid out at http://www.w3.org/TR/XMLHttpRequest/#the-response-attribute On browsers with no support for this (Chrome < 10, Firefox < 4, etc), only response types of DEFAULT or TEXT may be used, and the response returned will be the text response. On browsers with Mozilla's draft support for array buffers (Firefox 4, 5), only response types of DEFAULT, TEXT, and ARRAY_BUFFER may be used, and the response returned will be either the text response or the Mozilla implementation of the array buffer response. On browsers will full support, any valid response type supported by the browser may be used, and the response provided by the browser will be returned.

returns {*}
The response.

.getResponseHeader(key)

Get the value of the response-header with the given name from the Xhr object Will only return correct result when called from the context of a callback and the request has completed

key {string}
The name of the response-header to retrieve.
returns {string|undefined}
The value of the response-header named key.

.getResponseJson(opt_xssiPrefix)

Get the response and evaluates it as JSON from the Xhr object Will only return correct result when called from the context of a callback

opt_xssiPrefix {string=}
Optional XSSI prefix string to use for stripping of the response before parsing. This needs to be set only if your backend server prepends the same prefix string to the JSON response.
returns {Object|undefined}
JavaScript object.

.getResponseText()

Get the response text from the Xhr object Will only return correct result when called from the context of a callback.

returns {string}
Result from the server, or '' if no result available.

.getResponseType()

Gets the desired type for the response.

returns {goog.net.XhrIo.ResponseType}
The desired type for the response.

.getResponseXml()

Get the response XML from the Xhr object Will only return correct result when called from the context of a callback.

returns {Document}
The DOM Document representing the XML file, or null if no result available.

.getStatus()

Get the status from the Xhr object Will only return correct result when called from the context of a callback

returns {number}
Http status.

.getStatusText()

Get the status text from the Xhr object Will only return correct result when called from the context of a callback

returns {string}
Status text.

.getTimeoutInterval()

Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.

returns {number}
Timeout interval in milliseconds.

.getWithCredentials()

Gets whether a "credentialed" request is to be sent.

returns {boolean}
The desired type for the response.

.headers {goog.structs.Map}

Map of default headers to add to every request, use: XhrIo.headers.set(name, value)

.isActive()

returns {boolean}
Whether there is an active request.

.isComplete()

returns {boolean}
Whether the request has completed.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isSuccess()

returns {boolean}
Whether the request completed with a success.

.protectEntryPoints(errorHandler)

Installs exception protection for all entry point introduced by goog.net.XhrIo instances which are not protected by {@link goog.debug.ErrorHandler#protectWindowSetTimeout}, {@link goog.debug.ErrorHandler#protectWindowSetInterval}, or {@link goog.events.protectBrowserEventEntryPoint}.

errorHandler {goog.debug.ErrorHandler}
Error handler with which to protect the entry point(s).

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.removeEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.send(url, opt_callback, opt_method, opt_content, opt_headers, opt_timeoutInterval)

Static send that creates a short lived instance of XhrIo to send the request.

url {string|goog.Uri}
Uri to make request to.
opt_callback {Function=}
Callback function for when request is complete.
opt_method {string=}
Send method, default: GET.
opt_content {string|FormData|GearsBlob=}
Post data. This can be a Gears blob if the underlying HTTP request object is a Gears HTTP request.
opt_headers {Object|goog.structs.Map=}
Map of headers to add to the request.
opt_timeoutInterval {number=}
Number of milliseconds after which an incomplete request will be aborted; 0 means no timeout is set.
@see
goog.net.XhrIo.cleanup

.setParentEventTarget(parent)

Inherited from goog.events.EventTarget .

Sets the parent of this event target to use for bubbling.

parent {goog.events.EventTarget?}
Parent EventTarget (null if none).

.setResponseType(type)

Sets the desired type for the response. At time of writing, this is only supported in very recent versions of WebKit (10.0.612.1 dev and later). If this is used, the response may only be accessed via {@link #getResponse}.

type {goog.net.XhrIo.ResponseType}
The desired type for the response.

.setTimeoutInterval(ms)

Sets the number of milliseconds after which an incomplete request will be aborted and a {@link goog.net.EventType.TIMEOUT} event raised; 0 means no timeout is set.

ms {number}
Timeout interval in milliseconds; 0 means none.

.setWithCredentials(withCredentials)

Sets whether a "credentialed" request that is aware of cookie and authentication information should be made. This option is only supported by browsers that support HTTP Access Control. As of this writing, this option is not supported in IE.

withCredentials {boolean}
Whether this should be a "credentialed" request.