Properties Methods Events Config Options Direct Link

    Observable
      DataProxy
        HttpProxy

# Class Ext.data.HttpProxy

Package: | Ext.data
Defined In: | HttpProxy.js
Class: | HttpProxy
Extends: | DataProxy

An implementation of Ext.data.DataProxy that processes data requests within the same domain of the originating page.

Note: this class cannot be used to retrieve data from a domain other than the domain from which the running page was served. For cross-domain requests, use a ScriptTagProxy.

Be aware that to enable the browser to parse an XML document, the server must set the Content-Type header in the HTTP response to "`text/xml`".

## Config Options

Config Options | Defined By
--- | ---
| api : Object Specific urls to call on CRUD action methods "read", "create", "update" and "destroy". Defaults to:api: { read ... Specific urls to call on CRUD action methods "read", "create", "update" and "destroy". Defaults to:
    api: {
        read    : undefined,
        create  : undefined,
        update  : undefined,
        destroy : undefined
    }
The url is built based upon the action being executed `[load|create|save|destroy]` using the commensurate `api` property, or if undefined default to the configured Ext.data.Store.url. For example:
    api: {
        load :    '/controller/load',
        create :  '/controller/new',  // Server MUST return idProperty of new record
        save :    '/controller/update',
        destroy : '/controller/destroy_action'
    }

    // Alternatively, one can use the object-form to specify each API-action
    api: {
        load: {url: 'read.php', method: 'GET'},
        create: 'create.php',
        destroy: 'destroy.php',
        save: 'update.php'
    }
If the specific URL for a given CRUD action is undefined, the CRUD action request will be directed to the configured `url`. Note: To modify the URL for an action dynamically the appropriate API property should be modified before the action is requested using the corresponding before action event. For example to modify the URL associated with the load action:
    // modify the url for the action
    myStore.on({
        beforeload: {
            fn: function (store, options) {
                // use setUrl to change the URL for *just* this request.
                store.proxy.setUrl('changed1.php');

                // set optional second parameter to true to make this URL change
                // permanent, applying this URL for all subsequent requests.
                store.proxy.setUrl('changed1.php', true);

                // Altering the proxy API should be done using the public
                // method setApi.
                store.proxy.setApi('read', 'changed2.php');

                // Or set the entire API with a config-object.
                // When using the config-object option, you must redefine the entire
                // API -- not just a specific action of it.
                store.proxy.setApi({
                    read    : 'changed_read.php',
                    create  : 'changed_create.php',
                    update  : 'changed_update.php',
                    destroy : 'changed_destroy.php'
                });
            }
        }
    });
| DataProxy
| doRequest : Function Abstract method that should be implemented in all subclasses. Note: Should only be used by custom-proxy developers. ... Abstract method that should be implemented in all subclasses. Note: Should only be used by custom-proxy developers. (e.g.: HttpProxy.doRequest, DirectProxy.doRequest). | DataProxy
| 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 `click` event passing the node clicked on. To access DOM events directly from a Component's HTMLElement, listeners must be added to the Element after the Component has been rendered. A plugin can simplify this step:
    // Plugin is configured with a listeners config object.
    // The Component is appended to the argument list of all handler functions.
    Ext.DomObserver = Ext.extend(Object, {
        constructor: function(config) {
            this.listeners = config.listeners ? config.listeners : config;
        },

        // Component passes itself into plugin's init method
        init: function(c) {
            var p, l = this.listeners;
            for (p in l) {
                if (Ext.isFunction(l[p])) {
                    l[p] = this.createHandler(l[p], c);
                } else {
                    l[p].fn = this.createHandler(l[p].fn, c);
                }
            }

            // Add the listeners to the Element immediately following the render call
            c.render = c.render.createSequence(function() {
                var e = c.getEl();
                if (e) {
                    e.on(l);
                }
            });
        },

        createHandler: function(fn, c) {
            return function(e) {
                fn.call(this, e, c);
            };
        }
    });

    var combo = new Ext.form.ComboBox({

        // Collapse combo when its element is clicked on
        plugins: [ new Ext.DomObserver({
            click: function(evt, comp) {
                comp.collapse();
            }
        })],
        store: myStore,
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all'
    });
| Observable
| onRead : Function Abstract method that should be implemented in all subclasses. Note: Should only be used by custom-proxy developers. ... Abstract method that should be implemented in all subclasses. Note: Should only be used by custom-proxy developers. Callback for read action. | DataProxy
| onWrite : Function Abstract method that should be implemented in all subclasses. Note: Should only be used by custom-proxy developers. ... Abstract method that should be implemented in all subclasses. Note: Should only be used by custom-proxy developers. Callback for create, update and destroy actions. | DataProxy
| restful : Boolean Defaults to false. Set to true to operate in a RESTful manner. Note: this parameter will automatically be set to tr... Defaults to `false`. Set to `true` to operate in a RESTful manner. Note: this parameter will automatically be set to `true` if the Ext.data.Store it is plugged into is set to `restful: true`. If the Store is RESTful, there is no need to set this option on the proxy. RESTful implementations enable the serverside framework to automatically route actions sent to one url based upon the HTTP method, for example:
    store: new Ext.data.Store({
        restful: true,
        proxy: new Ext.data.HttpProxy({url:'/users'}); // all requests sent to /users
        ...
    )}
If there is no `api` specified in the configuration of the proxy, all requests will be marshalled to a single RESTful url (/users) so the serverside framework can inspect the HTTP Method and act accordingly:
    Method   url        action
    POST     /users     create
    GET      /users     read
    PUT      /users/23  update
    DESTROY  /users/23  delete
If set to `true`, a non-phantom record's id will be appended to the url. Some MVC (e.g., Ruby on Rails, Merb and Django) support segment based urls where the segments in the URL follow the Model-View-Controller approach:
    someSite.com/controller/action/id
Where the segments in the url are typically: The first segment : represents the controller class that should be invoked. The second segment : represents the class function, or method, that should be called. The third segment : represents the ID (a variable typically passed to the method). Refer to `Ext.data.DataProxy.api` for additional information. | DataProxy

## Public Properties

Property | Defined By
--- | ---
| conn : Object The Connection object (Or options parameter to Ext.Ajax.request) which this HttpProxy uses to make requests to the se... The Connection object (Or options parameter to Ext.Ajax.request) which this HttpProxy uses to make requests to the server. Properties of this object may be changed dynamically to change the way data is requested. | HttpProxy

## Public Methods

Method | Defined By
--- | ---
| HttpProxy( `Object conn` ) Parameters: `conn` : Object An Ext.data.Connection object, or options parameter to Ext.Ajax.request. Note that if this HttpProxy is being used by a Store, then the Store's call to load will override any specified `callback` and `params` options. In this case, use the Store's events to modify parameters, or react to loading events. The Store's baseParams may also be used to pass parameters known at instantiation time. If an options parameter is passed, the singleton Ext.Ajax object will be used to make the request. Returns: void | HttpProxy
- | addEvents( `Object|String o`, `string Optional.` ) : void Adds the specified events to the list of events which this Observable may fire. Adds the specified events to the list of events which this Observable may fire. Parameters: `o` : Object|String Either an object with event names as properties with a value of `true` or the first event name string if multiple event names are being passed as separate parameters. `Optional.` : string Event name if multiple event names are being passed as separate parameters. Usage:
      this.addEvents('storeloaded', 'storecleared');
Returns: void | Observable
- | addListener( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this object. Appends an event handler to this object. Parameters: `eventName` : String The name of the event to listen for. `handler` : Function The method the event invokes. `scope` : Object (optional) The scope (`this` reference) in which the handler function is executed. If omitted, defaults to the object which fired the event. `options` : Object (optional) An object containing handler configuration. properties. This may contain any of the following properties: scope : Object The scope (`this` reference) in which the handler function is executed. If omitted, defaults to the object which fired the event. delay : Number The number of milliseconds to delay the invocation of the handler after the 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. target : Observable Only call the handler if the event was fired on the target Observable, not if the event was bubbled up from a child Observable. Combining Options Using the options argument, it is possible to combine different types of listeners: A delayed, one-time listener.
      myDataView.on('click', this.onClick, this, {
      single: true,
      delay: 100
      });
  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.
      myGridPanel.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:
      myGridPanel.on({
      'click' : this.onClick,
      'mouseover' : this.onMouseOver,
      'mouseout' : this.onMouseOut,
       scope: this
      });
Returns: void | Observable
| destroy() : void Destroys the proxy by purging any event listeners and cancelling any active requests. Destroys the proxy by purging any event listeners and cancelling any active requests. Parameters: None. Returns: void | DataProxy
| doRequest( `String action`, `Ext.data.Record/Ext.data.Record[] rs`, `Object params`, `Ext.data.DataReader reader`, `Function callback`, `Object scope`, `Object arg` ) : void HttpProxy implementation of DataProxy#doRequest HttpProxy implementation of DataProxy#doRequest Parameters: `action` : String The crud action type (create, read, update, destroy) `rs` : Ext.data.Record/Ext.data.Record[] If action is load, rs will be null `params` : Object An object containing properties which are to be used as HTTP parameters for the request to the remote server. `reader` : Ext.data.DataReader The Reader object which converts the data object into a block of Ext.data.Records. `callback` : Function A function to be called after the request. The `callback` is passed the following arguments: `r` : Ext.data.Record[] The block of Ext.data.Records. `options`: Options object from the action request `success`: Boolean success indicator `scope` : Object The scope (`this` reference) in which the callback function is executed. Defaults to the browser window. `arg` : Object An optional argument which is passed to the callback as its second parameter. Returns: void | HttpProxy
| 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.getBubbleTarget()` if present. There is no implementation in the Observable base class. This is commonly used by Ext.Components to bubble events to owner Containers. See Ext.Component.getBubbleTarget. The default implementation in 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:
    Ext.override(Ext.form.Field, {
        //  Add functionality to Field's initComponent to enable the change event to bubble
        initComponent : Ext.form.Field.prototype.initComponent.createSequence(function() {
            this.enableBubble('change');
        }),

        //  We know that we want Field's events to bubble directly to the FormPanel.
        getBubbleTarget : function() {
            if (!this.formPanel) {
                this.formPanel = this.findParentByType('form');
            }
            return this.formPanel;
        }
    });

    var myForm = new Ext.formPanel({
        title: 'User Details',
        items: [{
            ...
        }],
        listeners: {
            change: function() {
                // Title goes red if form has been modified.
                myForm.header.setStyle('color', 'red');
            }
        }
    });
Parameters: `events` : String/Array The event name to bubble, or an Array of event names. Returns: void | Observable
| fireEvent( `String eventName`, `Object... args` ) : Boolean Fires 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: `eventName` : String The name of the event to fire. `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. | Observable
| getConnection() : Connection Return the Ext.data.Connection object being used by this Proxy. Return the Ext.data.Connection object being used by this Proxy. Parameters: None. Returns: `Connection` The Connection object. This object may be used to subscribe to events on a finer-grained basis than the DataProxy events. | HttpProxy
| hasListener( `String eventName` ) : Boolean Checks 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: `eventName` : String The name of the event to check for Returns: `Boolean` True if the event is being listened for, else false | Observable
| isApiAction( `String [Ext.data.Api.CREATE|READ|UPDATE|DESTROY]}` ) : Boolean Returns true if the specified action is defined as a unique action in the api-config. request. If all API-actions ar... Returns true if the specified action is defined as a unique action in the api-config. request. If all API-actions are routed to unique urls, the xaction parameter is unecessary. However, if no api is defined and all Proxy actions are routed to DataProxy#url, the server-side will require the xaction parameter to perform a switch to the corresponding code for CRUD action. Parameters: `[Ext.data.Api.CREATE|READ|UPDATE|DESTROY]}` : String action Returns: `Boolean` | DataProxy
| load( `Object params`, `Object reader`, `Object callback`, `Object scope`, `Object arg` ) : void Deprecated load method using old method signature. See {@doRequest} for preferred method. Deprecated load method using old method signature. See {@doRequest} for preferred method. Parameters: `params` : Object `reader` : Object `callback` : Object `scope` : Object `arg` : Object Returns: void | DataProxy
| on( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this object (shorthand for addListener.) Appends an event handler to this object (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 (`this` reference) in which the handler function is executed. If omitted, defaults to the object which fired the event. `options` : Object (optional) An object containing handler configuration. Returns: void | Observable
| onRead( `String action`, `Object o`, `Object res` ) : void Callback for read action Callback for read action Parameters: `action` : String Action name as per Ext.data.Api.actions.read. `o` : Object The request transaction object `res` : Object The server response Returns: void | HttpProxy
| onWrite( `String action`, `Object trans`, `Object res` ) : void Callback for write actions Callback for write actions Parameters: `action` : String [Ext.data.Api.actions.create|read|update|destroy] `trans` : Object The request transaction object `res` : Object The server response Returns: void | HttpProxy
| purgeListeners() : void Removes all listeners for this object Removes all listeners for this object Parameters: None. Returns: void | Observable
| 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: `o` : Object The Observable whose events this object is to relay. `events` : Array Array of event names to relay. Returns: void | Observable
| removeListener( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes an event handler. Removes an event handler. Parameters: `eventName` : String The type of event the handler was associated with. `handler` : Function The handler to remove. This must be a reference to the function passed into the addListener call. `scope` : Object (optional) The scope originally specified for the handler. Returns: void | Observable
| request( `String action`, `Ext.data.Record/Ext.data.Record[]/null rs`, `Object params`, `Ext.data.DataReader reader`, `Function callback`, `Object scope`, `Object options` ) : void All proxy actions are executed through this method. Automatically fires the "before" + action event All proxy actions are executed through this method. Automatically fires the "before" + action event Parameters: `action` : String Name of the action `rs` : Ext.data.Record/Ext.data.Record[]/null Will be null when action is 'load' `params` : Object `reader` : Ext.data.DataReader `callback` : Function `scope` : Object The scope (`this` reference) in which the callback function is executed. Defaults to the Proxy object. `options` : Object Any options specified for the action (e.g. see Ext.data.Store.load. Returns: void | DataProxy
| 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: None. Returns: void | Observable
| setApi( `String/Object api`, `String/Function url` ) : void Redefines the Proxy's API or a single action of an API. Can be called with two method signatures. If called with an o... Redefines the Proxy's API or a single action of an API. Can be called with two method signatures. If called with an object as the only parameter, the object should redefine the entire API, e.g.:
    proxy.setApi({
        read    : '/users/read',
        create  : '/users/create',
        update  : '/users/update',
        destroy : '/users/destroy'
    });
If called with two parameters, the first parameter should be a string specifying the API action to redefine and the second parameter should be the URL (or function if using DirectProxy) to call for that action, e.g.:
    proxy.setApi(Ext.data.Api.actions.read, '/users/new_load_url');
Parameters: `api` : String/Object An API specification object, or the name of an action. `url` : String/Function The URL (or function if using DirectProxy) to call for the action. Returns: void | DataProxy
| setUrl( `String url`, [`Boolean makePermanent`] ) : void Used for overriding the url used for a single request. Designed to be called during a beforeaction event. Calling s... Used for overriding the url used for a single request. Designed to be called during a beforeaction event. Calling setUrl will override any urls set via the api configuration parameter. Set the optional parameter makePermanent to set the url for all subsequent requests. If not set to makePermanent, the next request will use the same url or api configuration defined in the initial proxy configuration. Parameters: `url` : String `makePermanent` : Boolean (Optional) [false] (e.g.: beforeload, beforesave, etc). Returns: void | HttpProxy
| suspendEvents( `Boolean queueSuspended` ) : void Suspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters: `queueSuspended` : Boolean Pass as true to queue up suspended events to be fired after the resumeEvents call instead of discarding all suspended events; Returns: void | Observable
| un( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters: `eventName` : String The type of event the handler was associated with. `handler` : Function The handler to remove. This must be a reference to the function passed into the addListener call. `scope` : Object (optional) The scope originally specified for the handler. Returns: void | Observable

## Public Events

Event | Defined By
--- | ---
| beforeload : ( `DataProxy this`, `Object params` ) Fires before a request to retrieve a data object. Fires before a request to retrieve a data object. Listeners will be called with the following arguments: `this` : DataProxy The proxy for the request `params` : Object The params object passed to the request function | DataProxy
| beforewrite : ( `DataProxy this`, `String action`, `Record/Record[] rs`, `Object params` ) Fires before a request is generated for one of the actions Ext.data.Api.actions.create|update|destroy In addition to ... Fires before a request is generated for one of the actions Ext.data.Api.actions.create|update|destroy In addition to being fired through the DataProxy instance that raised the event, this event is also fired through the Ext.data.DataProxy class to allow for centralized processing of beforewrite events from all DataProxies by attaching a listener to the Ext.data.DataProxy class itself. Listeners will be called with the following arguments: `this` : DataProxy The proxy for the request `action` : String [Ext.data.Api.actions.create|update|destroy] `rs` : Record/Record[] The Record(s) to create|update|destroy. `params` : Object The request `params` object. Edit `params` to add parameters to the request. | DataProxy
| exception : ( `DataProxy this`, `String type`, `String action`, `Object options`, `Object response`, `Mixed arg` ) Fires if an exception occurs in the Proxy during a remote request. This event is relayed through a corresponding Ext.... Fires if an exception occurs in the Proxy during a remote request. This event is relayed through a corresponding Ext.data.Store.exception, so any Store instance may observe this event. In addition to being fired through the DataProxy instance that raised the event, this event is also fired through the Ext.data.DataProxy class to allow for centralized processing of exception events from all DataProxies by attaching a listener to the Ext.data.DataProxy class itself. This event can be fired for one of two reasons: remote-request failed : The server did not return status === 200. remote-request succeeded : The remote-request succeeded but the reader could not read the response. This means the server returned data, but the configured Reader threw an error while reading the response. In this case, this event will be raised and the caught error will be passed along into this event. This event fires with two different contexts based upon the 2nd parameter `type [remote|response]`. The first four parameters are identical between the two contexts -- only the final two parameters differ. Listeners will be called with the following arguments: `this` : DataProxy The proxy that sent the request `type` : String The value of this parameter will be either `'response'` or `'remote'`. `'response'` : An invalid response from the server was returned: either 404, 500 or the response meta-data does not match that defined in the DataReader (e.g.: root, idProperty, successProperty). `'remote'` : A valid response was returned from the server having successProperty === false. This response might contain an error-message sent from the server. For example, the user may have failed authentication/authorization or a database validation error occurred. `action` : String Name of the action (see Ext.data.Api.actions. `options` : Object The options for the action that were specified in the request. `response` : Object The value of this parameter depends on the value of the `type` parameter: `'response'` : The raw browser response object (e.g.: XMLHttpRequest) `'remote'` : The decoded response object sent from the server. `arg` : Mixed The type and value of this parameter depends on the value of the `type` parameter: `'response'` : Error The JavaScript Error object caught if the configured Reader could not read the data. If the remote request returns success===false, this parameter will be null. `'remote'` : Record/Record[] This parameter will only exist if the `action` was a write action (Ext.data.Api.actions.create|update|destroy). | DataProxy
| load : ( `DataProxy this`, `Object o`, `Object options` ) Fires before the load method's callback is called. Fires before the load method's callback is called. Listeners will be called with the following arguments: `this` : DataProxy The proxy for the request `o` : Object The request transaction object `options` : Object The callback's `options` property as passed to the request function | DataProxy
| loadexception : ( `misc misc` ) This event is deprecated. The signature of the loadexception event varies depending on the proxy, use the catch-all ... This event is deprecated. The signature of the loadexception event varies depending on the proxy, use the catch-all exception event instead. This event will fire in addition to the exception event. Listeners will be called with the following arguments: `misc` : misc See exception. | DataProxy
| write : ( `DataProxy this`, `String action`, `Object data`, `Object response`, `Record/Record[] rs`, `Object options` ) Fires before the request-callback is called In addition to being fired through the DataProxy instance that raised the... Fires before the request-callback is called In addition to being fired through the DataProxy instance that raised the event, this event is also fired through the Ext.data.DataProxy class to allow for centralized processing of write events from all DataProxies by attaching a listener to the Ext.data.DataProxy class itself. Listeners will be called with the following arguments: `this` : DataProxy The proxy that sent the request `action` : String [Ext.data.Api.actions.create|upate|destroy] `data` : Object The data object extracted from the server-response `response` : Object The decoded response from server `rs` : Record/Record[] The Record(s) from Store `options` : Object The callback's `options` property as passed to the request function | DataProxy