Observable Connection Ajax
Package: | Ext |
Defined In: | Connection.js |
Class: | Ajax |
Extends: | Connection |
The global Ajax request class that provides a simple way to make Ajax requests with maximum flexibility.
Since Ext.Ajax is a singleton, you can set common properties/events for it once and override them at the request function level only if necessary.
Common Properties you may want to set are:
// Default headers to pass in every request
Ext.Ajax.defaultHeaders = {
'Powered-By': 'Ext'
};
Common Events you may want to set are:
// Example: show a spinner during all Ajax requests
Ext.Ajax.on('beforerequest', this.showSpinner, this);
Ext.Ajax.on('requestcomplete', this.hideSpinner, this);
Ext.Ajax.on('requestexception', this.hideSpinner, this);
An example request:
// Basic request
Ext.Ajax.request({
url: 'foo.php',
success: someFn,
failure: otherFn,
headers: {
'my-header': 'foo'
},
params: { foo: 'bar' }
});
// Simple ajax form submission
Ext.Ajax.request({
form: 'some-form',
params: 'foo=bar'
});
Config Options | Defined By | |
---|---|---|
disableCachingParam : String Change the parameter which is sent went disabling caching
through a cache buster. Defaults to '_dc' | Connection | |
listeners : Object A config object containing one or more event handlers to be added to this
object during initialization. This should ... A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once. DOM events from ExtJs Components While some ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this
is usually only done when extra value can be added. For example the DataView's
| Observable |
Property | Defined By | |
---|---|---|
autoAbort : Boolean Whether a new request should abort any pending requests. (defaults to false) | Ajax | |
defaultHeaders : Object An object containing request headers which are added to each request made by this object
(defaults to undefined). | Ajax | |
disableCaching : Boolean True to add a unique cache-buster param to GET requests. (defaults to true) | Ajax | |
extraParams : Object An object containing properties which are used as extra parameters to each request made
by this object (defaults to ... An object containing properties which are used as extra parameters to each request made
by this object (defaults to undefined). Session information and other data that you need
to pass with each request are commonly put here. | Ajax | |
method : String The default HTTP method to be used for requests. Note that this is case-sensitive and
should be all caps (defaults t... The default HTTP method to be used for requests. Note that this is case-sensitive and
should be all caps (defaults to undefined; if not set but params are present will use
"POST", otherwise will use "GET".) | Ajax | |
timeout : Number The timeout in milliseconds to be used for requests. (defaults to 30000) | Ajax | |
url : String The default URL to be used for requests to the server. (defaults to undefined)
If the server receives all requests t... The default URL to be used for requests to the server. (defaults to undefined)
If the server receives all requests through one URL, setting this once is easier than
entering it on every request. | Ajax |
Method | Defined By | |
---|---|---|
abort( [Number transactionId ] )
:
voidAborts any outstanding request. Aborts any outstanding request. Parameters:
| Connection | |
addEvents( Object object )
:
voidUsed to define events on this Observable Used to define events on this Observable Parameters:
| Observable | |
addListener( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object. Appends an event handler to this object. Parameters:
| Observable | |
enableBubble( Object events )
:
voidUsed to enable bubbling of events Used to enable bubbling of events Parameters:
| Observable | |
fireEvent( String eventName , Object... args )
:
BooleanFires the specified event with the passed parameters (minus the event name).
An event may be set to bubble up an Obse... Fires the specified event with the passed parameters (minus the event name). An event may be set to bubble up an Observable parent hierarchy (See Ext.Component.getBubbleTarget) by calling enableBubble. Parameters:
| Observable | |
hasListener( String eventName )
:
BooleanChecks to see if this object has any listeners for a specified event Checks to see if this object has any listeners for a specified event Parameters:
| Observable | |
isLoading( [Number transactionId ] )
:
BooleanDetermine whether this object has a request outstanding. Determine whether this object has a request outstanding. Parameters:
| Connection | |
on( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object (shorthand for addListener.) Appends an event handler to this object (shorthand for addListener.) Parameters:
| Observable | |
purgeListeners()
:
void Removes all listeners for this object Removes all listeners for this object Parameters:
| Observable | |
relayEvents( Object o , Array events )
:
voidRelays selected events from the specified Observable as if the events were fired by this. Relays selected events from the specified Observable as if the events were fired by this. Parameters:
| Observable | |
removeListener( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler. Removes an event handler. Parameters:
| Observable | |
request( Object options )
:
NumberSends an HTTP request to a remote server.
Important: Ajax server requests are asynchronous, and this call will
retu... Sends an HTTP request to a remote server. Important: Ajax server requests are asynchronous, and this call will return before the response has been received. Process any returned data in a callback function.
To execute a callback function in the correct scope, use the scope option. Parameters:
| Connection | |
resumeEvents()
:
void Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
event... Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
events fired during event suspension will be sent to any listeners now. Parameters:
| Observable | |
serializeForm( String/HTMLElement form )
:
StringSerialize the passed form into a url encoded string Serialize the passed form into a url encoded string Parameters:
| Ajax | |
suspendEvents( Boolean queueSuspended )
:
voidSuspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters:
| Observable | |
un( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters:
| Observable |
Event | Defined By | |
---|---|---|
beforerequest :
( Connection conn , Object options )
Fires before a network request is made to retrieve a data object. Fires before a network request is made to retrieve a data object. Listeners will be called with the following arguments:
| Connection | |
requestcomplete :
( Connection conn , Object response , Object options )
Fires if the request was successfully completed. Fires if the request was successfully completed. Listeners will be called with the following arguments:
| Connection | |
requestexception :
( Connection conn , Object response , Object options )
Fires if an error HTTP status was returned from the server.
See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616... Fires if an error HTTP status was returned from the server.
See HTTP Status Code Definitions
for details of HTTP status codes. Listeners will be called with the following arguments:
| Connection |