Observable Proxy ServerProxy ScriptTagProxy
Package: | Ext.data |
Defined In: | ScriptTagProxy.js |
Class: | ScriptTagProxy |
Extends: | ServerProxy |
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 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 | |
---|---|---|
autoAppendParams : Boolean True to automatically append the request's params to the generated url. Defaults to true | ScriptTagProxy | |
batchOrder : String Comma-separated ordering 'create', 'update' and 'destroy' actions when batching. Override this
to set a different ord... Comma-separated ordering 'create', 'update' and 'destroy' actions when batching. Override this
to set a different order for the batched CRUD actions to be executed in. Defaults to 'create,update,destroy' | Proxy | |
cacheString : String The name of the cache param added to the url when using noCache (defaults to "_dc") | ServerProxy | |
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 | |
callbackPrefix : String The prefix string that is used to create a unique callback function name in the global scope. This can optionally
be ... The prefix string that is used to create a unique callback function name in the global scope. This can optionally
be modified to give control over how the callback string passed to the remote server is generated. Defaults to 'stcCallback' | ScriptTagProxy | |
defaultReaderType : String The default registered reader type. Defaults to 'json' | Proxy | |
defaultWriterType : String The default registered writer type. Defaults to 'json' | Proxy | |
extraParams : Object Extra parameters that will be included on every request. Individual requests with params
of the same name will overri... Extra parameters that will be included on every request. Individual requests with params
of the same name will override these params when they are in conflict. | ServerProxy | |
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. | ServerProxy | |
recordParam : String The param name to use when passing records to the server (e.g. 'records=someEncodedRecordString').
Defaults to 'recor... The param name to use when passing records to the server (e.g. 'records=someEncodedRecordString').
Defaults to 'records' | ScriptTagProxy | |
scriptIdPrefix : String The prefix string that is used to create a unique ID for the injected script tag element (defaults to 'stcScript') | ScriptTagProxy | |
timeout : Number The number of milliseconds to wait for a response. Defaults to 30 seconds. | ServerProxy | |
url : String The URL from which to request the data object. | ServerProxy |
Property | Defined By | |
---|---|---|
lastRequest : Ext.data.Request Reference to the most recent request made through this Proxy. Used internally to clean up when the Proxy is destroyed | ScriptTagProxy |
Method | Defined By | |
---|---|---|
abort()
:
void Aborts the current server request if one is currently running Aborts the current server request if one is currently running Parameters:
| ScriptTagProxy | |
addEvents( Object|String o , string Optional. )
:
voidAdds 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 ] )
:
voidAppends an event handler to this object. Appends an event handler to this object. Parameters:
| Observable | |
addManagedListener( Observable|Element item , Object|String ename , Function fn , Object scope , Object opt )
:
voidAdds listeners to any Observable object (or Element) which are automatically removed when this Component
is destroyed... Adds listeners to any Observable object (or Element) which are automatically removed when this Component is destroyed. Parameters:
| Observable | |
afterRequest( Ext.data.Request request , Boolean isLoaded )
:
voidCleans up after a completed request by removing the now unnecessary script tag from the DOM. Also removes the
global... Cleans up after a completed request by removing the now unnecessary script tag from the DOM. Also removes the
global JSON-P callback function. Parameters:
| ScriptTagProxy | |
batch( Object operations , Object listeners )
:
Ext.data.BatchPerforms a batch of Operations, in the order specified by batchOrder. Used internally by
Ext.data.Store's sync method... Performs a batch of Operations, in the order specified by batchOrder. Used internally by
Ext.data.Store's sync method. Example usage:
Where the myModel* above are Model instances - in this case 1 and 2 are new instances and have not been
saved before, 3 has been saved previously but needs to be updated, and 4 and 5 have already been saved but should now be destroyed.Parameters:
| Proxy | |
buildRequest( Ext.data.Operation operation )
:
Ext.data.RequestCreates and returns an Ext.data.Request object based on the options passed by the Store
that this Proxy is attached t... | ServerProxy | |
buildUrl( Ext.data.Request request )
:
StringGenerates a url based on a given Ext.data.Request object. Adds the params and callback function name to the url Generates a url based on a given Ext.data.Request object. Adds the params and callback function name to the url Parameters:
| ScriptTagProxy | |
clearListeners()
:
void Removes all listeners for this object including the managed listeners Removes all listeners for this object including the managed listeners Parameters:
| Observable | |
clearManagedListeners()
:
void Removes all managed listeners for this object. Removes all managed listeners for this object. Parameters:
| Observable | |
create( Ext.data.Operation operation , Function callback , Object scope )
:
voidPerforms the given create operation. Performs the given create operation. Parameters:
| Proxy | |
destroy( Ext.data.Operation operation , Function callback , Object scope )
:
voidPerforms the given destroy operation. Performs the given destroy operation. Parameters:
| Proxy | |
doRequest( Ext.data.Operation operation , Function callback , Object scope )
:
voidIn ServerProxy subclasses, the create, read, update and destroy methods all pass
through to doRequest. Each ServerPro... In ServerProxy subclasses, the create, read, update and destroy methods all pass
through to doRequest. Each ServerProxy subclass must implement the doRequest method - see Ext.data.ScriptTagProxy
and Ext.data.AjaxProxy for examples. This method carries the same signature as each of the methods that delegate to it. Parameters:
| ServerProxy | |
enableBubble( String/Array events )
:
voidEnables 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 | |
encodeRecords( Array records )
:
StringEncodes an array of records into a string suitable to be appended to the script src url. This is broken
out into its ... Encodes an array of records into a string suitable to be appended to the script src url. This is broken
out into its own function so that it can be easily overridden. Parameters:
| ScriptTagProxy | |
fireEvent( String eventName , Object... args )
:
BooleanFires 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 | |
getModel()
:
Ext.data.Model Returns the model attached to this Proxy Returns the model attached to this Proxy Parameters:
| Proxy | |
getReader()
:
Ext.data.Reader Returns the reader currently attached to this proxy instance Returns the reader currently attached to this proxy instance Parameters:
| Proxy | |
getWriter()
:
Ext.data.Writer Returns the writer currently attached to this proxy instance Returns the writer currently attached to this proxy instance Parameters:
| Proxy | |
hasListener( String eventName )
:
BooleanChecks 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 | |
on( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object (shorthand for addListener.) Appends an event handler to this object (shorthand for addListener.) Parameters:
| Observable | |
read( Ext.data.Operation operation , Function callback , Object scope )
:
voidPerforms the given read operation. Performs the given read operation. Parameters:
| Proxy | |
relayEvents( Object o , Array events )
:
voidRelays 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 ] )
:
voidRemoves an event handler. Removes an event handler. Parameters:
| Observable | |
removeManagedListener( Observable|Element item , Object|String ename , Function fn , Object scope )
:
voidRemoves listeners that were added by the mon method. Removes listeners that were added by the mon method. Parameters:
| Observable | |
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 | |
setModel( String|Ext.data.Model model , Boolean setOnStore )
:
voidSets the model associated with this proxy. This will only usually be called by a Store Sets the model associated with this proxy. This will only usually be called by a Store Parameters:
| Proxy | |
setReader( String|Object|Ext.data.Reader reader )
:
Ext.data.ReaderSets the Proxy's Reader by string, config object or Reader instance Sets the Proxy's Reader by string, config object or Reader instance Parameters:
| Proxy | |
setWriter( String|Object|Ext.data.Writer writer )
:
Ext.data.WriterSets the Proxy's Writer by string, config object or Writer instance Sets the Proxy's Writer by string, config object or Writer instance Parameters:
| Proxy | |
suspendEvents( Boolean queueSuspended )
:
voidSuspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters:
| Observable | |
un( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters:
| Observable | |
update( Ext.data.Operation operation , Function callback , Object scope )
:
voidPerforms the given update operation. Performs the given update operation. Parameters:
| Proxy |
Event | Defined By | |
---|---|---|
exception :
( Ext.data.Proxy this , Ext.data.Request request , Ext.data.Operation operation )
Fires when the server returns an exception Fires when the server returns an exception Listeners will be called with the following arguments:
| ScriptTagProxy |