Observable DataProxy ScriptTagProxy
Package: | Ext.data |
Defined In: | ScriptTagProxy.js |
Class: | ScriptTagProxy |
Extends: | DataProxy |
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 must be executable JavaScript
source code because it 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(");");
}
Below is a PHP example to do the same thing:
$callback = $_REQUEST['callback'];
// Create the output object.
$output = array('a' => 'Apple', 'b' => 'Banana');
//start output
if ($callback) {
header('Content-Type: text/javascript');
echo $callback . '(' . json_encode($output) . ');';
} else {
header('Content-Type: application/x-json');
echo json_encode($output);
}
Below is the ASP.Net code to do the same thing:
String jsonString = "{success: true}";
String cb = Request.Params.Get("callback");
String responseString = "";
if (!String.IsNullOrEmpty(cb)) {
responseString = cb + "(" + jsonString + ")";
} else {
responseString = jsonString;
}
Response.Write(responseString);
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:
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:
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:
| DataProxy | |
callbackParam : String The name of the parameter to pass to the server which tells
the server the name of the callback function set up by th... 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 | |
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
| Observable | |
nocache : Boolean Defaults to true. Disable caching by adding a unique parameter
name to the request. | ScriptTagProxy | |
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 implementations enable the serverside framework to automatically route actions sent to one url based upon the HTTP method, for example:
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:
Where the segments in the url are typically:
Refer to | DataProxy | |
timeout : Number 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 |
Method | Defined By | |
---|---|---|
ScriptTagProxy( Object config ) Parameters:
| ScriptTagProxy | |
abort() : void Abort the current server request. Abort the current server request. Parameters:
| ScriptTagProxy | |
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:
| 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:
| 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:
| 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:
| ScriptTagProxy | |
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 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:
Parameters:
| 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:
| 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:
| 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:
| 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:
| 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:
| Observable | |
onRead( String action, Object trans, Object res ) : void Callback for read actions Callback for read actions Parameters:
| ScriptTagProxy | |
onWrite( String action, Object trans, Object res ) : void Callback for write actions Callback for write actions Parameters:
| ScriptTagProxy | |
purgeListeners() : void Removes all listeners for this object Removes all listeners for this object Parameters:
| 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:
| Observable | |
removeListener( String eventName, Function handler, [Object scope] ) : void Removes an event handler. Removes an event handler. Parameters:
| 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:
| 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:
| 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.:
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.:
Parameters:
| DataProxy | |
suspendEvents( Boolean queueSuspended ) : void Suspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters:
| Observable | |
un( String eventName, Function handler, [Object scope] ) : void Removes an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters:
| Observable |
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:
| 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:
| 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:
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:
| 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:
| DataProxy | |
loadexception : ( Object this, Object options, Object arg, Error e ) Deprecated in favor of 'exception' event.
Fires if an exception occurs in the Proxy during data loading. This event ... Deprecated in favor of 'exception' event.
Fires if an exception occurs in the Proxy during data loading. This event can be fired for one of two reasons:
Listeners will be called with the following arguments:
| ScriptTagProxy | |
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:
| DataProxy |