Print Friendly

Class Ext.data.Connection

Package:Ext.data
Class:Connection
Extends:Observable
Subclasses:Ajax
Defined In:Connection.js
The class encapsulates a connection to the page's originating domain, allowing requests to be made either to a configured URL, or to a URL specified at request time.

Requests made by this class are asynchronous, and will return immediately. No data from the server will be available to the statement immediately following the request call. To process returned data, use a callback in the request options object, or an event listener.


Note: If you are doing a file upload, you will not get a normal response object sent back to your callback or event handler. Since the upload is handled via in IFRAME, there is no XMLHttpRequest. The response object is created using the innerHTML of the IFRAME's document as the responseText property and, if present, the IFRAME's XML document as the responseXML property.


This means that a valid XML or HTML document must be returned. If JSON data is required, it is suggested that it be placed either inside a <textarea> in an HTML document and retrieved from the responseText using a regex, or inside a CDATA section in an XML document and retrieved from the responseXML using standard DOM methods.

Properties   -  Methods   -  Events   -  Config Options

Public Properties

This class has no public properties.

Public Methods

Method Defined By
  ConnectionObject config ) Connection
  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.
  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...

Config Options

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

Constructor Details

Connection

public function Connection( Object config )
Parameters:
  • config : Object
    a configuration object.

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.

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.

Config Details

autoAbort

autoAbort : Boolean
(Optional) Whether this request should abort any pending requests. (defaults to false)
This config option is defined by Connection.

defaultHeaders

defaultHeaders : Object
(Optional) An object containing request headers which are added to each request made by this object. (defaults to undefined)
This config option is defined by Connection.

disableCaching

disableCaching : Boolean
(Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
This config option is defined by Connection.

extraParams

extraParams : Object
(Optional) An object containing properties which are used as extra parameters to each request made by this object. (defaults to undefined)
This config option is defined by Connection.

method

method : String
(Optional) 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 config option is defined by Connection.

timeout

timeout : Number
(Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
This config option is defined by Connection.

url

url : String
(Optional) The default URL to be used for requests to the server. (defaults to undefined)
This config option is defined by Connection.

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