goog.testing.net.XhrIo.base
Provided By | |
---|---|
Extends | |
All Implemented Interfaces | |
All Known Direct Subclasses | |
Alias for |
Some compiled tests replace goog.net.XhrIo with goog.testing.net.XhrIo, which would cause a circular constructor loop.
new base( opt_xmlHttpFactory )
Parameters |
|
---|
Instance Methods
this.abort( opt_failureCode ) → void
void
Abort the current XMLHttpRequest
Parameters |
|
---|
this.addEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
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.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.addOnDisposeCallback<T>( callback, opt_scope ) → void
void
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added. If a callback is added to an already disposed Disposable, it will be called immediately.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.createXhr() → (goog.net.XhrLike|XMLHttpRequest)
(goog.net.XhrLike|XMLHttpRequest)
Creates a new XHR object.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.dispatchEvent( e ) → boolean
boolean
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.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.dispose() → ?
?
Disposes of the object and its resources.
Overrides | ||
---|---|---|
Specified by | ||
Parameters | None. | |
Returns |
|
this.disposeInternal() → void
void
Nullifies all callbacks to reduce risks of leaks.
Overrides | |
---|---|
Parameters | None. |
this.fireListeners<EVENTOBJ>( type, capture, eventObject ) → boolean
boolean
Fires all registered listeners in this listenable for the given type and capture mode, passing them the given eventObject. This does not perform actual capture/bubble. Only implementors of the interface should be using this.
Overrides | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||
Parameters |
| ||||||||||||
Returns |
|
this.getAllResponseHeaders() → string
string
Gets the text of all the headers in the response.
Will only return correct result after ready state reaches LOADED
(i.e.
HEADERS_RECEIVED
as per MDN).
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getAllStreamingResponseHeaders() → string
string
Gets the text of all the headers in the response. As opposed to
#getAllResponseHeaders
, this method does not require that the request
has completed.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getDisposed() → boolean
boolean
warning Deprecated | Use |
---|
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getLastError() → string
string
this.getLastErrorCode() → goog.net.ErrorCode
goog.net.ErrorCode
this.getLastUri() → string
string
this.getListener<SCOPE, EVENTOBJ>( type, listener, capture, opt_listenerScope ) → (goog.events.ListenableKey|null)
(goog.events.ListenableKey|null)
Gets the goog.events.ListenableKey for the event or null if no such listener is in use.
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.getListeners<EVENTOBJ>( type, capture ) → Array<goog.events.ListenableKey>
Array<goog.events.ListenableKey>
Gets all listeners in this listenable for the given type and capture mode.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.getParentEventTarget() → (goog.events.Listenable|null)
(goog.events.Listenable|null)
Returns the parent of this event target to use for capture/bubble mechanism.
NOTE(chrishenry): The name reflects the original implementation of
custom event target (goog.events.EventTarget
). We decided
that changing the name is not worth it.
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.getProgressEventsEnabled() → boolean
boolean
Gets whether progress events are enabled.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getReadyState() → goog.net.XmlHttp.ReadyState
goog.net.XmlHttp.ReadyState
Get the readystate from the Xhr object Will only return correct result when called from the context of a callback
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.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 < 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.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getResponseBody() → (Object|null)
(Object|null)
Get the response body from the Xhr object. This property is only available in IE since version 7 according to MSDN: http://msdn.microsoft.com/en-us/library/ie/ms534368(v=vs.85).aspx Will only return correct result when called from the context of a callback.
One option is to construct a VBArray from the returned object and convert
it to a JavaScript array using the toArray method:
(new window['VBArray'](xhrIo.getResponseBody())).toArray()
This will result in an array of numbers in the range of [0..255]
Another option is to use the VBScript CStr method to convert it into a string as outlined in http://stackoverflow.com/questions/1919972
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getResponseHeader( key ) → (string|undefined)
(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
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
Returns all response headers as a key-value map. Multiple values for the same header key can be combined into one, separated by a comma and a space. Note that the native getResponseHeader method for retrieving a single header does a case insensitive match on the header name. This method does not include any case normalization logic, it will just return a key-value representation of the headers. See: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getResponseJson( opt_xssiPrefix ) → (Object|null|undefined)
(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
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
| ||||
Throws |
|
this.getResponseText() → string
string
Get the response text from the Xhr object Will only return correct result when called from the context of a callback.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getResponseType() → goog.net.XhrIo.ResponseType
goog.net.XhrIo.ResponseType
Gets the desired type for the response.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getResponseXml() → (Document|null)
(Document|null)
Get the response XML from the Xhr object Will only return correct result when called from the context of a callback.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getStatus() → number
number
Get the status from the Xhr object Will only return correct result when called from the context of a callback
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getStatusText() → string
string
Get the status text from the Xhr object Will only return correct result when called from the context of a callback
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getStreamingResponseHeader( key ) → (string|null)
(string|null)
Get the value of the response-header with the given name from the Xhr object.
As opposed to #getResponseHeader
, this method does not require that
the request has completed.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.getTimeoutInterval() → number
number
Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getWithCredentials() → boolean
boolean
Gets whether a "credentialed" request is to be sent.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.hasListener<EVENTOBJ>( opt_type, opt_capture ) → boolean
boolean
Whether there is any active listeners matching the specified signature. If either the type or capture parameters are unspecified, the function will match on the remaining criteria.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.isActive() → boolean
boolean
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.isComplete() → boolean
boolean
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.isDisposed() → boolean
boolean
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.isSuccess() → boolean
boolean
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.listen<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener. A listener can only be added once to an object and if it is added again the key for the listener is returned. Note that if the existing listener is a one-off listener (registered via listenOnce), it will no longer be a one-off listener after a call to listen().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.listenOnce<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener that is removed automatically after the listener fired once.
If an existing listener already exists, listenOnce will do nothing. In particular, if the listener was previously registered via listen(), listenOnce() will not turn the listener into a one-off listener. Similarly, if there is already an existing one-off listener, listenOnce does not modify the listeners (it is still a once listener).
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.registerDisposable( disposable ) → void
void
Associates a disposable object with this object so that they will be disposed together.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.removeAllListeners( opt_type ) → number
number
Removes all listeners from this listenable. If type is specified, it will only remove listeners of the particular type. otherwise all registered listeners will be removed.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.removeEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
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.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.send( url, opt_method, opt_content, opt_headers ) → void
void
Instance send that actually uses XMLHttpRequest to make a server call.
Parameters |
|
---|
this.setParentEventTarget( parent ) → void
void
Sets the parent of this event target to use for capture/bubble mechanism.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setProgressEventsEnabled( enabled ) → void
void
Sets whether progress events are enabled for this request. Note that progress events require pre-flight OPTIONS request handling for CORS requests, and may cause trouble with older browsers. See progressEventsEnabled_ for details.
Parameters |
|
---|
this.setResponseType( type ) → void
void
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
.
Parameters |
|
---|
this.setTargetForTesting( target ) → void
void
Sets the target to be used for event.target
when firing
event. Mainly used for testing. For example, see
goog.testing.events.mixinListenable
.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTimeoutInterval( ms ) → void
void
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.
Parameters |
|
---|
this.setTrustToken( trustToken ) → void
void
Specify a Trust Tokens operation to execute alongside the request.
Parameters |
|
---|
this.setWithCredentials( withCredentials ) → void
void
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.
Parameters |
|
---|
this.unlisten<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → boolean
boolean
Removes an event listener which was added with listen() or listenOnce().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.unlistenByKey( key ) → boolean
boolean
Removes an event listener which was added with listen() by the key returned by listen().
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
Instance Properties
this.creationStack → (string|undefined)
(string|undefined)
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Map of default headers to add to every request, use: XhrIo.headers.set(name, value)
Static Functions
base.cleanup() → void
void
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'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.
base.protectEntryPoints( errorHandler ) → void
void
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
.
Parameters |
|
---|
base.send( url, opt_callback, opt_method, opt_content, opt_headers, opt_timeoutInterval, opt_withCredentials ) → goog.net.XhrIo
goog.net.XhrIo
Static send that creates a short lived instance of XhrIo to send the request.
Parameters |
| ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
| ||||||||||||||||||||||||||||
See Also |
Static Properties
base.CONTENT_TRANSFER_ENCODING → string
string
The Content-Transfer-Encoding HTTP header name
base.CONTENT_TYPE_HEADER → string
string
The Content-Type HTTP header name
base.FORM_CONTENT_TYPE → string
string
The Content-Type HTTP header value for a url-encoded form
base.HTTP_SCHEME_PATTERN → RegExp
RegExp
The pattern matching the 'http' and 'https' URI schemes
The methods that typically come along with form data. We set different headers depending on whether the HTTP action is one of these.