Properties Methods Events Config Options Direct Link

    Observable
      DataProxy
        ScriptTagProxy

# Class Ext.data.ScriptTagProxy

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

An implementation of Ext.data.DataProxy that reads a data object from a URL which may be in a domain other than the originating domain of the running page.

Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, rather than HttpProxy.

The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript source code that is used as the source inside a <script> tag.

In order for the browser to process the returned data, the server must wrap the data object with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy. Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy depending on whether the callback name was passed:

    boolean scriptTag = false;
    String cb = request.getParameter("callback");
    if (cb != null) {
        scriptTag = true;
        response.setContentType("text/javascript");
    } else {
        response.setContentType("application/x-json");
    }
    Writer out = response.getWriter();
    if (scriptTag) {
        out.write(cb + "(");
    }
    out.print(dataBlock.toJsonString());
    if (scriptTag) {
        out.write(");");
    }

## Config Options

Config Options | Defined By
--- | ---
| callbackParam : String (Optional) The name of the parameter to pass to the server which tells the server the name of the callback function s... (Optional) The name of the parameter to pass to the server which tells the server the name of the callback function set up by the load call to process the returned data object. Defaults to "callback". The server-side processing must read this parameter value, and generate javascript output which calls this named function passing the data object as its only parameter. | ScriptTagProxy
| listeners : Object A config object containing one or more event handlers to be added to this object during initialization. This should b... 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. | Observable
| nocache : Boolean (Optional) Defaults to true. Disable cacheing by adding a unique parameter name to the request. | ScriptTagProxy
| timeout : Number (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds. | ScriptTagProxy
| url : String The URL from which to request the data object. | ScriptTagProxy

## Public Properties

This class has no public properties.

## Public Methods

Method | Defined By
--- | ---
| ScriptTagProxy( `Object config` ) Parameters: `config` : Object A configuration object. Returns: `` | ScriptTagProxy
| abort() : void Abort the current server request. Abort the current server request. Parameters: None. Returns: `void` | ScriptTagProxy
| addEvents( `Object object` ) : void Used to define events on this Observable Used to define events on this Observable Parameters: `object` : Object The object with the events defined Returns: `void` | Observable
- | addListener( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this component 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 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. 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.
      foo.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:
      foo.on({
          'click' : this.onClick,
          'mouseover' : this.onMouseOver,
          'mouseout' : this.onMouseOut,
           scope: this
      });
Returns: `void` | Observable
| fireEvent( `String eventName`, `Object... args` ) : Boolean Fires the specified event with the passed parameters (minus the event name). 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 | Observable
| 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
| load( `Object params`, `Ext.data.DataReader reader`, `Function callback`, `Object scope`, `Object arg` ) : void Load data from the configured URL, read the data object into a block of Ext.data.Records using the passed Ext.data.Da... Load data from the configured URL, read the data object into a block of Ext.data.Records using the passed Ext.data.DataReader implementation, and process that block using the passed callback. Parameters: `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 The function into which to pass the block of Ext.data.Records. The function must be passed The Record block object The "arg" argument from the load function A boolean success indicator `scope` : Object The scope in which to call the callback `arg` : Object An optional argument which is passed to the callback as its second parameter. Returns: `void` | ScriptTagProxy
| on( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this element (shorthand for addListener) 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` | Observable
| purgeListeners() : void Removes all listeners for this object Removes all listeners for this object Parameters: None. Returns: `void` | Observable
| removeListener( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes a listener 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` | Observable
| resumeEvents() : void Resume firing events. (see suspendEvents) Resume firing events. (see suspendEvents) Parameters: None. Returns: `void` | Observable
| suspendEvents() : void Suspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters: None. Returns: `void` | Observable
| un( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes a listener (shorthand for removeListener) 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` | Observable

## Public Events

Event | Defined By
--- | ---
| beforeload : ( `Object This`, `Object params` ) 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: `This` : Object DataProxy object. `params` : Object The params parameter to the load function. | DataProxy
| load : ( `Object This`, `Object o`, `Object arg` ) 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` : Object DataProxy object. `o` : Object The data object. `arg` : Object The callback argument object passed to the load function. | DataProxy
| loadexception : ( `Object This`, `Object o`, `Object arg`, `Object e` ) Fires if an Exception occurs during data retrieval. Fires if an Exception occurs during data retrieval. Listeners will be called with the following arguments: `This` : Object DataProxy object. `o` : Object The data object. `arg` : Object The callback argument object passed to the load function. `e` : Object The Exception. | DataProxy