ObservableConnection
Ajax
| Package: | CQ.Ext |
| Class: | Ajax |
| Extends: | CQ.Ext.data.Connection |
| Clientlib: | cq.widgets |
The global Ajax request class that provides a simple way to make Ajax requests with maximum flexibility.
Since CQ.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
CQ.Ext.Ajax.defaultHeaders = {
'Powered-By': 'CQ.Ext'
};
Common Events you may want to set are:
// Example: show a spinner during all Ajax requests
CQ.Ext.Ajax.on('beforerequest', this.showSpinner, this);
CQ.Ext.Ajax.on('requestcomplete', this.hideSpinner, this);
CQ.Ext.Ajax.on('requestexception', this.hideSpinner, this);
An example request:
// Basic request
CQ.Ext.Ajax.request({
url: 'foo.php',
success: someFn,
failure: otherFn,
headers: {
'my-header': 'foo'
},
params: { foo: 'bar' }
});
// Simple ajax form submission
CQ.Ext.Ajax.request({
form: 'some-form',
params: 'foo=bar'
});
| Config Options | Defined By | |
|---|---|---|
|
disableCachingParam : String
(Optional) Change the parameter which is sent went disabling caching through a cache buster. Defaults to '_dc'
|
Connection | |
| Method | Defined By | |
|---|---|---|
abort( [Number transactionId] ) : void Aborts any outstanding request.
Aborts any outstanding request.
Parameters:
|
Connection | |
enableBubble( String/Array events ) : void Enables events fired by this Observable to bubble up an owner hierarchy by calling
this.getBubbleTarget() if present....
Enables events fired by this Observable to bubble up an owner hierarchy by calling
This is commonly used by CQ.Ext.Components to bubble events to owner Containers. See CQ.Ext.Component.getBubbleTarget. The default implementation in CQ.Ext.Component returns the Component's immediate owner. But if a known target is required, this can be overridden to access the required target more quickly. Example:
Parameters:
|
Observable | |
isLoading( [Number transactionId] ) : Boolean Determine whether this object has a request outstanding.
Determine whether this object has a request outstanding.
Parameters:
|
Connection | |
relayEvents( Object o, Array events ) : void Relays 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 | |
request( [Object options] ) : Number Sends an HTTP request to a remote server.
Important: Ajax server requests are asynchronous, and this call will
return...
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 | |
serializeForm( String/HTMLElement form ) : String Serialize the passed form into a url encoded string
Serialize the passed form into a url encoded string
Parameters:
|
Ajax | |
| 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 HTTP Status Code Definitions
for details of HTTP stat...
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 | |