net.XhrIo Extends goog.events.EventTarget
Basic class for handling XMLHttpRequests.

Inheritance

Constructor

goog.net.XhrIo(opt_xmlHttpFactory)

Parameters

opt_xmlHttpFactory :
(goog.net.XmlHttpFactory | null | undefined)
Factory to use when creating XMLHttpRequest objects.

Instance Methods

Public Protected Private
Defined in goog.net.XhrIo
abort(opt_failureCode)
Abort the current XMLHttpRequest
Arguments:
opt_failureCode :
(goog.net.ErrorCode.<number> | undefined)
Optional error code to use - defaults to ABORT.
code »
cleanUpXhr_(opt_fromDispose)
Remove the listener to protect against leaks, and nullify the XMLHttpRequest object.
Arguments:
opt_fromDispose :
(boolean | undefined)
If this is from the dispose (don't want to fire any events).
code »
createXhr()
(GearsHttpRequest | XMLHttpRequest | null)
Creates a new XHR object.
Returns: 
(GearsHttpRequest | XMLHttpRequest | null)
  The newly created XHR object.
code »
dispatchErrors_()
Dispatches COMPLETE and ERROR in case of an error. This ensures that we do not dispatch multiple error events.
code »
disposeInternal()
Nullifies all callbacks to reduce risks of leaks.
code »
error_(errorCodeerr)
Something errorred, so inactivate, fire error callback and clean up
Arguments:
errorCode :
goog.net.ErrorCode.<number>
The error code.
err :
(Error | null)
The error object.
code »
formatMsg_(msg)
Adds the last method, status and URI to the message. This is used to add this information to the logging calls.
Arguments:
msg :
The message text that we want to add the extra text to.
Returns:   The message with the extra text appended.
code »
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:   The value of the response headers or empty string.
code »
getLastError()
Get the last error message
Returns:   Last error message.
code »
getLastErrorCode()
goog.net.ErrorCode.<number>
Get the last error message
Returns: 
goog.net.ErrorCode.<number>
  Last error code.
code »
getLastUri()
Get the last Uri that was requested
Returns:   Last Uri.
code »
getReadyState()
goog.net.XmlHttp.ReadyState.<number>
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.<number>
  goog.net.XmlHttp.ReadyState.*.
code »
getResponse()
*
Get the response as the type specificed by #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 &lt; 10, Firefox &lt; 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&#39;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.
code »
getResponseHeader(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
Arguments:
key :
The name of the response-header to retrieve.
Returns: 
(string | undefined)
  The value of the response-header named key.
code »
getResponseJson(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
Arguments:
opt_xssiPrefix :
(string | undefined)
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 | null | undefined)
  JavaScript object.
code »
getResponseText()
Get the response text from the Xhr object Will only return correct result when called from the context of a callback.
Returns:   Result from the server, or '' if no result available.
code »
getResponseType()
goog.net.XhrIo.ResponseType.<string>
Gets the desired type for the response.
Returns: 
goog.net.XhrIo.ResponseType.<string>
  The desired type for the response.
code »
getResponseXml()
(Document | null)
Get the response XML from the Xhr object Will only return correct result when called from the context of a callback.
Returns: 
(Document | null)
  The DOM Document representing the XML file, or null if no result available.
code »
getStatus()
Get the status from the Xhr object Will only return correct result when called from the context of a callback
Returns:   Http status.
code »
getStatusText()
Get the status text from the Xhr object Will only return correct result when called from the context of a callback
Returns:   Status text.
code »
getTimeoutInterval()
Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
Returns:   Timeout interval in milliseconds.
code »
getWithCredentials()
Gets whether a "credentialed" request is to be sent.
Returns:   The desired type for the response.
code »
isActive()
No description.
Returns:   Whether there is an active request.
code »
isComplete()
No description.
Returns:   Whether the request has completed.
code »
isLastUriEffectiveSchemeHttp_()
No description.
Returns:   whether the effective scheme of the last URI that was fetched was 'http' or 'https'.
code »
isSuccess()
No description.
Returns:   Whether the request completed with a success.
code »
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. #protectEntryPoints
code »
onReadyStateChangeHelper_()
Helper for #onReadyStateChange_. This is used so that entry point calls to #onReadyStateChange_ can be routed through #onReadyStateChangeEntryPoint_.
code »
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.
code »
send(urlopt_methodopt_contentopt_headers)
Instance send that actually uses XMLHttpRequest to make a server call.
Arguments:
url :
(goog.Uri | null | string)
Uri to make request to.
opt_method :
(string | undefined)
Send method, default: GET.
opt_content :
(ArrayBuffer | Blob | Document | FormData | GearsBlob | null | string | undefined)
Post data. This can be a Gears blob if the underlying HTTP request object is a Gears HTTP request.
opt_headers :
(Object | null | undefined)
Map of headers to add to the request.
code »
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 #getResponse.
Arguments:
type :
goog.net.XhrIo.ResponseType.<string>
The desired type for the response.
code »
setTimeoutInterval(ms)
Sets the number of milliseconds after which an incomplete request will be aborted and a goog.net.EventType.TIMEOUT event raised; 0 means no timeout is set.
Arguments:
ms :
Timeout interval in milliseconds; 0 means none.
code »
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.
Arguments:
withCredentials :
Whether this should be a "credentialed" request.
code »
timeout_()
The request didn&#39;t complete after goog.net.XhrIo#timeoutInterval_ milliseconds; raises a goog.net.EventType.TIMEOUT event and aborts the request.
code »
addEventListener(typehandleropt_captureopt_handlerScope)
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.
Arguments:
type :
The type of the event to listen for.
handler :
(Object | null)
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 | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
code »
dispatchEvent(e)
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.
Arguments:
e :
(Object | null | string)
Event object.
Returns:   If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.
code »
disposeInternal()
Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:
MyClass.prototype.disposeInternal = function() {
MyClass.superClass_.disposeInternal.call(this);
// Dispose logic for MyClass
};
code »
getParentEventTarget()
Returns the parent of this event target to use for bubbling.
Returns:   The parent EventTarget or null if there is no parent.
code »
removeEventListener(typehandleropt_captureopt_handlerScope)
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.
Arguments:
type :
The type of the event to listen for.
handler :
(Object | null)
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 | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
code »
setParentEventTarget(parent)
Sets the parent of this event target to use for bubbling.
Arguments:
parent :
Parent EventTarget (null if none).
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback :
?function (this:T):
The callback function.
opt_scope :
(T | undefined)
An optional scope to call the callback in.
code »
dispose()
undefined
Disposes of the object. If the object hasn&amp;#39;t already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: 
undefined
  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass&amp;#39; disposeInternal method. Everywhere else the public dispose method must be used. For example:
mypackage.MyClass = function() {
goog.base(this);
// Constructor logic specific to MyClass.
...
};
goog.inherits(mypackage.MyClass, goog.Disposable);

mypackage.MyClass.prototype.disposeInternal = function() {
// Dispose logic specific to MyClass.
...
// Call superclass&#39;s disposeInternal at the end of the subclass&#39;s, like
// in C++, to avoid hard-to-catch issues.
goog.base(this, &#39;disposeInternal&#39;);
};
code »
getDisposed()
Use #isDisposed instead. No description.
Returns:   Whether the object has been disposed of.
code »
isDisposed()
No description.
Returns:   Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable :
that will be disposed when this object is disposed.
code »

Instance Properties

Defined in goog.net.XhrIo
active_ :
Whether XMLHttpRequest is active. A request is active from the time send() is called until onReadyStateChange() is complete, or error() or abort() is called.
Code »
errorDispatched_ :
This is used to ensure that we don't dispatch an multiple ERROR events. This can happen in IE when it does a synchronous load and one error is handled in the ready statte change and one is handled due to send() throwing an exception.
Code »
headers :
(goog.structs.Map | null)
Map of default headers to add to every request, use: XhrIo.headers.set(name, value)
Code »
inAbort_ :
Used in determining if a call to #onReadyStateChange_ is from within a call to this.xhr_.abort.
Code »
inOpen_ :
Used in determining if a call to #onReadyStateChange_ is from within a call to this.xhr_.open.
Code »
inSend_ :
Used to make sure we don't fire the complete event from inside a send call.
Code »
lastErrorCode_ :
goog.net.ErrorCode.<number>
Last error code.
Code »
lastError_ :
(Error | null | string)
Last error message.
Code »
lastMethod_ :
Method for the last request.
Code »
lastUri_ :
(goog.Uri | null | string)
Last URL that was requested.
Code »
logger_ :
A reference to the XhrIo logger
Code »
responseType_ :
goog.net.XhrIo.ResponseType.<string>
The requested type for the response. The empty string means use the default XHR behavior.
Code »
timeoutId_ :
(Object | null)
Window timeout ID used to cancel the timeout event handler if the request completes successfully.
Code »
timeoutInterval_ :
Number of milliseconds after which an incomplete request will be aborted and a goog.net.EventType.TIMEOUT event raised; 0 means no timeout is set.
Code »
withCredentials_ :
Whether a "credentialed" request is to be sent (one that is aware of cookies and authentication) . This is applicable only for cross-domain requests and more recent browsers that support this part of the HTTP Access Control standard.
Code »
xhrOptions_ :
(Object | null)
The options to use with the current XMLHttpRequest object.
Code »
xhr_ :
(GearsHttpRequest | XMLHttpRequest | null)
Reference to an XMLHttpRequest object that is being used for the transfer.
Code »
xmlHttpFactory_ :
Optional XmlHttpFactory
Code »
customEvent_ :
Used to tell if an event is a real event in goog.events.listen() so we don't get listen() calling addEventListener() and vice-versa.
Code »
parentEventTarget_ :
Parent event target, used during event bubbling.
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
dependentDisposables_ :
(Array.<(goog.disposable.IDisposable | null)> | null)
Disposables that should be disposed when this object is disposed.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
(Array.<Function> | null)
Callbacks to invoke when this object is disposed.
Code »

Static Methods

goog.net.XhrIo.cleanup()
Disposes all non-disposed instances of goog.net.XhrIo created by goog.net.XhrIo.send. 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 goog.net.XhrIo.send return the goog.net.XhrIo it creates and make the client of 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 goog.net.XhrIo.send is that it&#39;s simple and easy to use. Clients of goog.net.XhrIo.send should call goog.net.XhrIo.cleanup when doing final cleanup on window unload.
code »
goog.net.XhrIo.cleanupSend_(XhrIo)
Disposes of the specified goog.net.XhrIo created by goog.net.XhrIo.send and removes it from goog.net.XhrIo.pendingStaticSendInstances_.
Arguments:
XhrIo :
(goog.net.XhrIo | null)
An XhrIo created by goog.net.XhrIo.send.
code »
goog.net.XhrIo.protectEntryPoints(errorHandleropt_tracers)
Installs exception protection for all entry point introduced by goog.net.XhrIo instances which are not protected by goog.debug.ErrorHandler#protectWindowSetTimeout, goog.debug.ErrorHandler#protectWindowSetInterval, or goog.events.protectBrowserEventEntryPoint.
Arguments:
errorHandler :
Error handler with which to protect the entry point(s).
opt_tracers :
(boolean | undefined)
Whether to install tracers around the entry point.
code »
goog.net.XhrIo.send(urlopt_callbackopt_methodopt_contentopt_headersopt_timeoutIntervalopt_withCredentials)
Static send that creates a short lived instance of XhrIo to send the request.
Arguments:
url :
Uri to make request too.
opt_callback :
(Function | null | undefined)
Callback function for when request is complete.
opt_method :
(string | undefined)
Send method, default: GET.
opt_content :
(string | undefined)
Post data.
opt_headers :
(Object | null | undefined)
Map of headers to add to the request.
opt_timeoutInterval :
(number | undefined)
Number of milliseconds after which an incomplete request will be aborted; 0 means no timeout is set.
opt_withCredentials :
No description.
code »

Static Properties

goog.net.XhrIo.CONTENT_TYPE_HEADER :
The Content-Type HTTP header name
Code »
goog.net.XhrIo.FORM_CONTENT_TYPE :
The Content-Type HTTP header value for a url-encoded form
Code »
goog.net.XhrIo.HTTP_SCHEME_PATTERN :
The pattern matching the 'http' and 'https' URI schemes
Code »
goog.net.XhrIo.sendInstances_ :
(Array.<(goog.net.XhrIo | null)> | null)
All non-disposed instances of goog.net.XhrIo created by goog.net.XhrIo.send are in this Array.
Code »

Enumerations

goog.net.XhrIo.ResponseType :
Response types that may be requested for XMLHttpRequests.
Constants:
DEFAULT
No description.
ARRAY_BUFFER
No description.
BLOB
No description.
DOCUMENT
No description.
TEXT
No description.
Code »

Package net

Package Reference