goog.net.XhrIo
Classgoog.net.XhrIo
> goog.events.EventTarget
> goog.Disposable
goog.net.XhrIo(opt_xmlHttpFactory)
Basic class for handling XMLHttpRequests.
opt_xmlHttpFactory
{goog.net.XmlHttpFactory
=}
.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
goog.net.XhrIo.ResponseType
EnumResponse types that may be requested for XMLHttpRequests. … more
.abort(opt_failureCode)
Abort the current XMLHttpRequest
opt_failureCode
{goog.net.ErrorCode
=}
.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
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.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
}
opt_scope
{Object
=}
.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.
.createXhr()
[protected]Creates a new XHR object.
XMLHttpRequest
|GearsHttpRequest
}
.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
}
boolean
}
.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.
void
}
.disposeInternal()
[protected]Nullifies all callbacks to reduce risks of leaks.
.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.
string
}
.getDisposed
[deprecated]Deprecated. Use {@link #isDisposed} instead.
Inherited from goog.Disposable
.
boolean
}
.getLastError()
Get the last error message
string
}
.getLastErrorCode()
Get the last error message
goog.net.ErrorCode
}
.getLastUri()
Get the last Uri that was requested
string
}
.getParentEventTarget()
Inherited from goog.events.EventTarget
.
Returns the parent of this event target to use for bubbling.
goog.events.EventTarget
}
.getReadyState()
Get the readystate from the Xhr object Will only return correct result when called from the context of a callback
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.
.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
}
string
|undefined
}
.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
=}
Object
|undefined
}
.getResponseText()
Get the response text from the Xhr object Will only return correct result when called from the context of a callback.
string
}
.getResponseType()
Gets the desired type for the response.
goog.net.XhrIo.ResponseType
}
.getResponseXml()
Get the response XML from the Xhr object Will only return correct result when called from the context of a callback.
Document
}
.getStatus()
Get the status from the Xhr object Will only return correct result when called from the context of a callback
number
}
.getStatusText()
Get the status text from the Xhr object Will only return correct result when called from the context of a callback
string
}
.getTimeoutInterval()
Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
number
}
.getWithCredentials()
Gets whether a "credentialed" request is to be sent.
boolean
}
.headers
{goog.structs.Map
}Map of default headers to add to every request, use: XhrIo.headers.set(name, value)
.isActive()
boolean
}
.isComplete()
boolean
}
.isDisposed()
Inherited from goog.Disposable
.
boolean
}
.isSuccess()
boolean
}
.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
}
.registerDisposable(disposable)
Inherited from goog.Disposable
.
Associates a disposable object with this object so that they will be disposed together.
disposable
{goog.disposable.IDisposable
}
.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
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.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
}
opt_callback
{Function
=}
opt_method
{string
=}
opt_content
{string
|FormData
|GearsBlob
=}
opt_headers
{Object
|goog.structs.Map
=}
opt_timeoutInterval
{number
=}
.setParentEventTarget(parent)
Inherited from goog.events.EventTarget
.
Sets the parent of this event target to use for bubbling.
parent
{goog.events.EventTarget
?}
.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
}
.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
}
.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
}