Home

# Class goog.net.XhrIo

Basic class for handling XMLHttpRequests.

extends goog.events.EventTarget

Instance Method Summary
| `abort(?goog.net.ErrorCode= opt_failureCode)` Abort the current XMLHttpRequest
| `cleanUpXhr_(boolean= opt_fromDispose)` Remove the listener to protect against leaks, and nullify the XMLHttpRequest object.
| `createXhr() ⇒ (GearsHttpRequest|XMLHttpRequest|null)` Creates a new XHR object.
| `dispatchErrors_()` Dispatches COMPLETE and ERROR in case of an error. This ensures that we do not dispatch multiple error events.
| `disposeInternal()` Nullifies all callbacks to reduce risks of leaks.
| `error_(?goog.net.ErrorCode errorCode, ?Error err)` Something errorred, so inactivate, fire error callback and clean up
| `formatMsg_(string msg) ⇒ string` Adds the last method, status and URI to the message. This is used to add this information to the logging calls.
| `getAllResponseHeaders() ⇒ string` 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.
| `getLastError() ⇒ string` Get the last error message
| `getLastErrorCode() ⇒ ?goog.net.ErrorCode` Get the last error message
| `getLastUri() ⇒ string` Get the last Uri that was requested
| `getReadyState() ⇒ ?goog.net.XmlHttp.ReadyState` Get the readystate from the Xhr object Will only return correct result when called from the context of a callback

`getResponse() ⇒ <Any Type>`

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://dev.w3.org/2006/webapi/XMLHttpRequest-2/#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.

| `getResponseHeader(string key) ⇒ (string|undefined)` 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
| `getResponseJson(string= opt_xssiPrefix) ⇒ (Object|null|undefined)` 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
| `getResponseText() ⇒ string` Get the response text from the Xhr object Will only return correct result when called from the context of a callback.
| `getResponseType() ⇒ ?goog.net.XhrIo.ResponseType` Gets the desired type for the response.
| `getResponseXml() ⇒ ?Document` Get the response XML from the Xhr object Will only return correct result when called from the context of a callback.
| `getStatus() ⇒ number` Get the status from the Xhr object Will only return correct result when called from the context of a callback
| `getStatusText() ⇒ string` Get the status text from the Xhr object Will only return correct result when called from the context of a callback
| `getTimeoutInterval() ⇒ number` Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
| `getWithCredentials() ⇒ boolean` Gets whether a "credentialed" request is to be sent.
| `isActive() ⇒ boolean`
| `isComplete() ⇒ boolean`
| `isLastUriEffectiveSchemeHttp_() ⇒ boolean`
| `isSuccess() ⇒ boolean`
| `onReadyStateChangeEntryPoint_()` Used to protect the onreadystatechange handler entry point. Necessary as {#onReadyStateChange_} maybe called from within send or abort, this method is only called when {#onReadyStateChange_} is called as an entry point. {@see #protectEntryPoints}
| `onReadyStateChangeHelper_()` Helper for {@link #onReadyStateChange_}. This is used so that entry point calls to {@link #onReadyStateChange_} can be routed through {@link #onReadyStateChangeEntryPoint_}.
| `onReadyStateChange_()` Internal handler for the XHR object's readystatechange event. This method checks the status and the readystate and fires the correct callbacks. If the request has ended, the handlers are cleaned up and the XHR object is nullified.
| `send((goog.Uri|null|string) url, string= opt_method, (GearsBlob|null|string=) opt_content, (Object|goog.structs.Map|null=) opt_headers)` Instance send that actually uses XMLHttpRequest to make a server call.
| `setResponseType(?goog.net.XhrIo.ResponseType 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}.
| `setTimeoutInterval(number 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.
| `setWithCredentials(boolean 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.
| `timeout_()` The request didn't complete after {@link goog.net.XhrIo#timeoutInterval_} milliseconds; raises a {@link goog.net.EventType.TIMEOUT} event and aborts the request.

Static Method Summary

`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.

| `cleanupSend_(?goog.net.XhrIo XhrIo)` Disposes of the specified goog.net.XhrIo created by {@link goog.net.XhrIo.send} and removes it from {@link goog.net.XhrIo.pendingStaticSendInstances_}.
| `protectEntryPoints(?goog.debug.ErrorHandler 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}.
| `send((goog.Uri|null|string) url, ?Function= opt_callback, string= opt_method, (GearsBlob|null|string=) opt_content, (Object|goog.structs.Map|null=) opt_headers, number= opt_timeoutInterval)` Static send that creates a short lived instance of XhrIo to send the request.