Print Friendly

Class Ext.Ajax

Package:Ext
Class:Ajax
Extends:Connection
Defined In:Connection.js
Global Ajax request class.

This class is a singleton and cannot be created directly.

Properties   -  Methods   -  Events

Public Properties

Property Defined By
  autoAbort : Boolean Ajax
Whether a new request should abort any pending requests. (defaults to false)
  defaultHeaders : Object Ajax
An object containing request headers which are added to each request made by this object. (defaults to undefined)
  disableCaching : Boolean Ajax
True to add a unique cache-buster param to GET requests. (defaults to true)
  extraParams : Object Ajax
An object containing properties which are used as extra parameters to each request made by this object. (defaults to...
  method : String Ajax
The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use P...
  timeout : Number Ajax
The timeout in milliseconds to be used for requests. (defaults to 30000)
  url : String Ajax
The default URL to be used for requests to the server. (defaults to undefined)

Public Methods

Method Defined By
  abort[Number transactionId] ) : void Connection
Aborts any outstanding request.
  addEventsObject object ) : void Observable
Used to define events on this Observable
  addListenerString eventName, Function handler, [Object scope], [Object options] ) : void Observable
Appends an event handler to this component
  fireEventString eventName, Object... args ) : Boolean Observable
Fires the specified event with the passed parameters (minus the event name).
  hasListenerString eventName ) : Boolean Observable
Checks to see if this object has any listeners for a specified event
  isLoading[Number transactionId] ) : Boolean Connection
Determine whether this object has a request outstanding.
  onString eventName, Function handler, [Object scope], [Object options] ) : void Observable
Appends an event handler to this element (shorthand for addListener)
  purgeListeners() : void Observable
Removes all listeners for this object
  removeListenerString eventName, Function handler, [Object scope] ) : void Observable
Removes a listener
  request[Object options] ) : Number Connection
Sends an HTTP request to a remote server.
  serializeFormString/HTMLElement form ) : String Ajax
Serialize the passed form into a url encoded string
  unString eventName, Function handler, [Object scope] ) : void Observable
Removes a listener (shorthand for removeListener)

Public Events

Event Defined By
  beforerequest : ( Connection conn, Object options ) Connection
Fires before a network request is made to retrieve a data object.
  requestcomplete : ( Connection conn, Object response, Object options ) Connection
Fires if the request was successfully completed.
  requestexception : ( Connection conn, Object response, Object options ) Connection
Fires if an error HTTP status was returned from the server. See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-se...

Property Details

autoAbort

public Boolean autoAbort
Whether a new request should abort any pending requests. (defaults to false)
This property is defined by Ajax.

defaultHeaders

public Object defaultHeaders
An object containing request headers which are added to each request made by this object. (defaults to undefined)
This property is defined by Ajax.

disableCaching

public Boolean disableCaching
True to add a unique cache-buster param to GET requests. (defaults to true)
This property is defined by Ajax.

extraParams

public Object extraParams
An object containing properties which are used as extra parameters to each request made by this object. (defaults to undefined)
This property is defined by Ajax.

method

public String method
The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
This property is defined by Ajax.

timeout

public Number timeout
The timeout in milliseconds to be used for requests. (defaults to 30000)
This property is defined by Ajax.

url

public String url
The default URL to be used for requests to the server. (defaults to undefined)
This property is defined by Ajax.

Method Details

abort

public function abort( [Number transactionId] )
Aborts any outstanding request.
Parameters:
  • transactionId : Number
    (Optional) defaults to the last transaction
Returns:
  • void
This method is defined by Connection.

addEvents

public function addEvents( Object object )
Used to define events on this Observable
Parameters:
  • object : Object
    The object with the events defined
Returns:
  • void
This method is defined by Observable.

addListener

public function addListener( String eventName, Function handler, [Object scope], [Object options] )
Appends an event handler to this component
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The method the event invokes
  • scope : Object
    (optional) The scope in which to execute the handler function. The handler function's "this" context.
  • options : Object
    (optional) An object containing handler configuration properties. This may contain any of the following properties:
    • scope {Object} The scope in which to execute the handler function. The handler function's "this" context.
    • delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.
    • single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.
    • buffer {Number} Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place.

    Combining Options
    Using the options argument, it is possible to combine different types of listeners:

    A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)

    el.on('click', this.onClick, this, {
     			single: true,
        		delay: 100,
        		forumId: 4
    		});

    Attaching multiple handlers in 1 call
    The method also allows for a single argument to be passed which is a config object containing properties which specify multiple handlers.

    el.on({
    			'click': {
            		fn: this.onClick,
            		scope: this,
            		delay: 100
        		}, 
        		'mouseover': {
            		fn: this.onMouseOver,
            		scope: this
        		},
        		'mouseout': {
            		fn: this.onMouseOut,
            		scope: this
        		}
    		});

    Or a shorthand syntax which passes the same scope object to all handlers:

    el.on({
    			'click': this.onClick,
        		'mouseover': this.onMouseOver,
        		'mouseout': this.onMouseOut,
        		scope: this
    		});
Returns:
  • void
This method is defined by Observable.

fireEvent

public function fireEvent( String eventName, Object... args )
Fires the specified event with the passed parameters (minus the event name).
Parameters:
  • eventName : String
  • args : Object...
    Variable number of parameters are passed to handlers
Returns:
  • Boolean
    returns false if any of the handlers return false otherwise it returns true
This method is defined by Observable.

hasListener

public function hasListener( String eventName )
Checks to see if this object has any listeners for a specified event
Parameters:
  • eventName : String
    The name of the event to check for
Returns:
  • Boolean
    True if the event is being listened for, else false
This method is defined by Observable.

isLoading

public function isLoading( [Number transactionId] )
Determine whether this object has a request outstanding.
Parameters:
  • transactionId : Number
    (Optional) defaults to the last transaction
Returns:
  • Boolean
    True if there is an outstanding request.
This method is defined by Connection.

on

public function on( String eventName, Function handler, [Object scope], [Object options] )
Appends an event handler to this element (shorthand for addListener)
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The method the event invokes
  • scope : Object
    (optional) The scope in which to execute the handler function. The handler function's "this" context.
  • options : Object
    (optional)
Returns:
  • void
This method is defined by Observable.

purgeListeners

public function purgeListeners()
Removes all listeners for this object
Parameters:
  • None.
Returns:
  • void
This method is defined by Observable.

removeListener

public function removeListener( String eventName, Function handler, [Object scope] )
Removes a listener
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The handler to remove
  • scope : Object
    (optional) The scope (this object) for the handler
Returns:
  • void
This method is defined by Observable.

request

public function request( [Object options] )
Sends an HTTP request to a remote server.
Parameters:
  • options : Object
    An object which may contain the following properties:
    • url {String} (Optional) The URL to which to send the request. Defaults to configured URL
    • params {Object/String/Function} (Optional) An object containing properties which are used as parameters to the request, a url encoded string or a function to call to get either.
    • method {String} (Optional) The HTTP method to use for the request. Defaults to the configured method, or if no method was configured, "GET" if no parameters are being sent, and "POST" if parameters are being sent.
    • callback {Function} (Optional) The function to be called upon receipt of the HTTP response. The callback is called regardless of success or failure and is passed the following parameters:
      • options {Object} The parameter to the request call.
      • success {Boolean} True if the request succeeded.
      • response {Object} The XMLHttpRequest object containing the response data.
    • success {Function} (Optional) The function to be called upon success of the request. The callback is passed the following parameters:
      • response {Object} The XMLHttpRequest object containing the response data.
      • options {Object} The parameter to the request call.
    • failure {Function} (Optional) The function to be called upon failure of the request. The callback is passed the following parameters:
      • response {Object} The XMLHttpRequest object containing the response data.
      • options {Object} The parameter to the request call.
    • scope {Object} (Optional) The scope in which to execute the callbacks: The "this" object for the callback function. Defaults to the browser window.
    • form {Object/String} (Optional) A form object or id to pull parameters from.
    • isUpload {Boolean} (Optional) True if the form object is a file upload (will usually be automatically detected).
    • headers {Object} (Optional) Request headers to set for the request.
    • xmlData {Object} (Optional) XML document to use for the post. Note: This will be used instead of params for the post data. Any params will be appended to the URL.
    • disableCaching {Boolean} (Optional) True to add a unique cache-buster param to GET requests.
Returns:
  • Number
    transactionId
This method is defined by Connection.

serializeForm

public function serializeForm( String/HTMLElement form )
Serialize the passed form into a url encoded string
Parameters:
  • form : String/HTMLElement
Returns:
  • String
This method is defined by Ajax.

un

public function un( String eventName, Function handler, [Object scope] )
Removes a listener (shorthand for removeListener)
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The handler to remove
  • scope : Object
    (optional) The scope (this object) for the handler
Returns:
  • void
This method is defined by Observable.

Event Details

beforerequest

public event beforerequest
Fires before a network request is made to retrieve a data object.
Subscribers will be called with the following parameters:
  • conn : Connection
    This Connection object.
  • options : Object
    The options config object passed to the request method.
This event is defined by Connection.

requestcomplete

public event requestcomplete
Fires if the request was successfully completed.
Subscribers will be called with the following parameters:
  • conn : Connection
    This Connection object.
  • response : Object
    The XHR object containing the response data. See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
  • options : Object
    The options config object passed to the request method.
This event is defined by Connection.

requestexception

public event requestexception
Fires if an error HTTP status was returned from the server. See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html} for details of HTTP status codes.
Subscribers will be called with the following parameters:
  • conn : Connection
    This Connection object.
  • response : Object
    The XHR object containing the response data. See {@link http://www.w3.org/TR/XMLHttpRequest/} for details.
  • options : Object
    The options config object passed to the request method.
This event is defined by Connection.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.