Ext.NET  5.3.0
.NET Component Framework for Enterprise Level Apps
Ext.Net.JsonPProxy Class Reference

JsonPProxy is useful when you need to load data from a domain other than the one your application is running on. If your application is running on http://domainA.com it cannot use Ajax to load its data from http://domainB.com because cross-domain ajax requests are prohibited by the browser.We can get around this using a JsonPProxy. JsonPProxy injects a <script> tag into the DOM whenever an AJAX request would usually be made. Let's say we want to load data from http://domainB.com/users - the script tag that would be injected might look like this:<script src="http://domainB.com/users?callback=someCallback"></script> When we inject the tag above, the browser makes a request to that url and includes the response as if it was any other type of JavaScript include. By passing a callback in the url above, we're telling domainB's server that we want to be notified when the result comes in and that it should call our callback function with the data it sends back. So long as the server formats the response to look like this, everything will work:someCallback({ users: [ { id: 1, name: "Ed Spencer", email: "ed@sencha.com" } ] }); As soon as the script finishes loading, the 'someCallback' function that we passed in the url is called with the JSON object that the server returned.JsonPProxy takes care of all of this automatically. It formats the url you pass, adding the callback parameter automatically. It even creates a temporary callback function, waits for it to be called and then puts the data into the Proxy making it look just like you loaded it through a normal AjaxProxy. Here's how we might set that up:Ext.regModel('User', { fields: ['id', 'name', 'email'] });var store = new Ext.data.Store({ model: 'User', proxy: { type: 'jsonp', url : 'http://domainB.com/users' } });store.load(); That's all we need to do - JsonPProxy takes care of the rest. In this case the Proxy will have injected a script tag like this:<script src="http://domainB.com/users?callback=stcCallback001" id="stcScript001"></script> CustomizationMost parts of this script tag can be customized using the callbackParam, callbackPrefix and scriptIdPrefix configurations. For example:var store = new Ext.data.Store({ model: 'User', proxy: { type: 'jsonp', url : 'http://domainB.com/users', callbackParam: 'theCallbackFunction', callbackPrefix: 'ABC', scriptIdPrefix: 'injectedScript' } });store.load(); Would inject a script tag like this:<script src="http://domainB.com/users?theCallbackFunction=ABC001" id="injectedScript001"></script> Implementing on the server sideThe remote server side needs to be configured to return data in this format. Here are suggestions for how you might achieve this using ASP.net:ASP.net: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);More information is available here: http://en.wikipedia.org/wiki/JSONP More...

Inheritance diagram for Ext.Net.JsonPProxy:
Ext.Net.ServerProxy Ext.Net.AbstractProxy Ext.Net.BaseItem Ext.Net.IAlias Ext.Net.IXObject Ext.Net.IBase

Classes

class  Builder
 
class  Config
 

Public Member Functions

 JsonPProxy ()
 
JsonPProxy.Builder ToBuilder ()
 
override IControlBuilder ToNativeBuilder ()
 
 JsonPProxy (Config config)
 
- Public Member Functions inherited from Ext.Net.BaseItem
virtual bool HasExplicitValue (string name)
 
void EnsureDataBind ()
 
virtual void Call (string name)
 
virtual void Call (string name, params object[] args)
 
virtual void AddScript (string script)
 
virtual void AddScript (string script, params object[] args)
 
virtual bool IsEmptyObject ()
 
Apply< T > (IApply config)
 
BaseItem Apply (object config)
 
virtual void LoadViewState (object state)
 
virtual object SaveViewState ()
 
virtual void TrackViewState ()
 
void SetDirty ()
 
virtual void DataBind ()
 

Static Public Member Functions

static implicit operator JsonPProxy (JsonPProxy.Config config)
 

Properties

override string InstanceOf [get]
 
override string Type [get]
 Alias More...
 
virtual bool AutoAppendParams [get, set]
 True to automatically append the request's params to the generated url. Defaults to true More...
 
virtual string CallbackKey [get, set]
 Specifies the GET parameter that will be sent to the server containing the function name to be executed when the request completes. Defaults to callback. Thus, a common request will be in the form of url?callback=Ext.data.JsonP.callback1 More...
 
virtual string RecordParam [get, set]
 The param name to use when passing records to the server (e.g. 'records=someEncodedRecordString'). Defaults to 'records' More...
 
override ConfigOptionsCollection ConfigOptions [get]
 
- Properties inherited from Ext.Net.ServerProxy
override string InstanceOf [get]
 
virtual CRUDUrls?? API [get]
 Specific urls to call on CRUD action methods "read", "create", "update" and "destroy". 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. If the specific URL for a given CRUD action is undefined, the CRUD action request will be directed to the configured url. More...
 
virtual string CacheString [get, set]
 The name of the cache param added to the url when using noCache (defaults to "_dc") More...
 
virtual string DirectionParam [get, set]
 The name of the direction parameter to send in a request. This is only used when simpleSortMode is set to true. Defaults to 'dir'. More...
 
virtual ParameterCollection?? ExtraParams [get]
 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. More...
 
virtual string FilterParam [get, set]
 The name of the 'filter' parameter to send in a request. Defaults to 'filter'. Set this to undefined if you don't want to send a filter parameter More...
 
virtual string GroupParam [get, set]
 The name of the 'group' parameter to send in a request. Defaults to 'group'. Set this to undefined if you don't want to send a group parameter More...
 
virtual string GroupDirectionParam [get, set]
 The name of the direction parameter to send in a request. This is only used when simpleGroupMode is set to true. Defaults to 'groupDir'. More...
 
virtual string IDParam [get, set]
 The name of the parameter which carries the id of the entity being operated upon. Defaults to: "id" More...
 
virtual string LimitParam [get, set]
 The name of the 'limit' parameter to send in a request. Defaults to 'limit'. Set this to undefined if you don't want to send a limit parameter More...
 
virtual bool NoCache [get, set]
 Defaults to true. Disable caching by adding a unique parameter name to the request. Set to false to allow caching. Defaults to true. More...
 
virtual bool AppendAction [get, set]
 
virtual string PageParam [get, set]
 The name of the 'page' parameter to send in a request. Defaults to 'page'. Set this to undefined if you don't want to send a page parameter More...
 
virtual ReaderCollection?? Reader [get]
 The Ext.data.reader.Reader to use to decode the server's response. This can either be a Reader instance, a config object or just a valid Reader type name (e.g. 'json', 'xml'). More...
 
virtual bool SimpleSortMode [get, set]
 Enabling simpleSortMode in conjunction with remoteSort will only send one sort property and a direction when a remote sort is requested. The directionParam and sortParam will be sent with the property name and either 'ASC' or 'DESC'. Defaults to: false More...
 
virtual bool SimpleGroupMode [get, set]
 Enabling simpleGroupMode in conjunction with remoteGroup will only send one group property and a direction when a remote group is requested. The groupDirectionParam and groupParam will be sent with the property name and either 'ASC' or 'DESC'. Defaults to: false More...
 
virtual string SortParam [get, set]
 The name of the 'sort' parameter to send in a request. Defaults to 'sort'. Set this to undefined if you don't want to send a sort parameter More...
 
virtual string StartParam [get, set]
 The name of the 'start' parameter to send in a request. Defaults to 'start'. Set this to undefined if you don't want to send a start parameter More...
 
virtual int Timeout [get, set]
 The number of milliseconds to wait for a response. Defaults to 30000 milliseconds (30 seconds). More...
 
virtual string Url [get, set]
 The default URL to be used for requests to the server. More...
 
virtual string UrlProxy [get]
 
virtual string StartParamProxy [get]
 
virtual string LimitParamProxy [get]
 
virtual WriterCollection?? Writer [get]
 The Ext.data.writer.Writer to use to encode any request sent to the server. This can either be a Writer instance, a config object or just a valid Writer type name (e.g. 'json', 'xml'). More...
 
ProxyListeners?? Listeners [get]
 Client-side JavaScript Event Handlers More...
 
virtual JFunction BuildUrl [get]
 Generates a url based on a given Ext.data.Request object. By default, ServerProxy's buildUrl will add the cache-buster param to the end of the url. Subclasses may need to perform additional modifications to the url. Parameters request : Ext.data.Request The request object Returns The url More...
 
override ConfigOptionsCollection ConfigOptions [get]
 
- Properties inherited from Ext.Net.AbstractProxy
override string InstanceOf [get]
 
abstract string Type [get]
 Alias More...
 
virtual bool BatchActions [get, set]
 True to batch actions of a particular type when synchronizing the store. Defaults to true. More...
 
virtual string BatchOrder [get, set]
 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' More...
 
string PropertyName [get]
 
override ConfigOptionsCollection ConfigOptions [get]
 
- Properties inherited from Ext.Net.BaseItem
virtual string InstanceOf [get]
 
ItemState State [get]
 
virtual DefaultValueMode DefaultValueMode [get, set]
 
virtual bool DesignMode [get]
 
bool AutoDataBind [get, set]
 
ResourceManager ResourceManager [get]
 
virtual Control Owner [get, set]
 The Owner Control for this Listener. More...
 
virtual bool IsDefault [get]
 Does this object currently represent it's default state. More...
 
bool IsTrackingViewState [get]
 
EventHandlerList Events [get]
 
EventHandler DataBinding
 
Control?? BindingContainer [get]
 
virtual ConfigItemCollection?? CustomConfig [get]
 Collection of custom js config More...
 
virtual ConfigOptionsCollection ConfigOptions [get]
 
virtual ConfigOptionsExtraction ConfigOptionsExtraction [get]
 
System.Web.Mvc.HtmlHelper?? HtmlHelper [get, set]
 
- Properties inherited from Ext.Net.IXObject
ConfigOptionsCollection ConfigOptions [get]
 
ConfigOptionsExtraction ConfigOptionsExtraction [get]
 
DefaultValueMode DefaultValueMode [get, set]
 
- Properties inherited from Ext.Net.IAlias
string PropertyName [get]
 

Additional Inherited Members

- Protected Member Functions inherited from Ext.Net.BaseItem
 BaseItem (Control owner)
 
 BaseItem ()
 
virtual void OwnerUpdate (Control owner)
 
virtual void OnDataBinding (EventArgs e)
 

Detailed Description

JsonPProxy is useful when you need to load data from a domain other than the one your application is running on. If your application is running on http://domainA.com it cannot use Ajax to load its data from http://domainB.com because cross-domain ajax requests are prohibited by the browser.

We can get around this using a JsonPProxy. JsonPProxy injects a <script> tag into the DOM whenever an AJAX request would usually be made. Let's say we want to load data from http://domainB.com/users - the script tag that would be injected might look like this:

<script src="http://domainB.com/users?callback=someCallback"></script> When we inject the tag above, the browser makes a request to that url and includes the response as if it was any other type of JavaScript include. By passing a callback in the url above, we're telling domainB's server that we want to be notified when the result comes in and that it should call our callback function with the data it sends back. So long as the server formats the response to look like this, everything will work:

someCallback({ users: [ { id: 1, name: "Ed Spencer", email: "ed@sencha.com" } ] }); As soon as the script finishes loading, the 'someCallback' function that we passed in the url is called with the JSON object that the server returned.

JsonPProxy takes care of all of this automatically. It formats the url you pass, adding the callback parameter automatically. It even creates a temporary callback function, waits for it to be called and then puts the data into the Proxy making it look just like you loaded it through a normal AjaxProxy. Here's how we might set that up:

Ext.regModel('User', { fields: ['id', 'name', 'email'] });

var store = new Ext.data.Store({ model: 'User', proxy: { type: 'jsonp', url : 'http://domainB.com/users' } });

store.load(); That's all we need to do - JsonPProxy takes care of the rest. In this case the Proxy will have injected a script tag like this:

<script src="http://domainB.com/users?callback=stcCallback001" id="stcScript001"></script> Customization

Most parts of this script tag can be customized using the callbackParam, callbackPrefix and scriptIdPrefix configurations. For example:

var store = new Ext.data.Store({ model: 'User', proxy: { type: 'jsonp', url : 'http://domainB.com/users', callbackParam: 'theCallbackFunction', callbackPrefix: 'ABC', scriptIdPrefix: 'injectedScript' } });

store.load(); Would inject a script tag like this:

<script src="http://domainB.com/users?theCallbackFunction=ABC001" id="injectedScript001"></script> Implementing on the server side

The remote server side needs to be configured to return data in this format. Here are suggestions for how you might achieve this using ASP.net:

ASP.net:

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);

More information is available here: http://en.wikipedia.org/wiki/JSONP

Constructor & Destructor Documentation

◆ JsonPProxy() [1/2]

Ext.Net.JsonPProxy.JsonPProxy ( )
inline

◆ JsonPProxy() [2/2]

Ext.Net.JsonPProxy.JsonPProxy ( Config  config)
inline

Member Function Documentation

◆ operator JsonPProxy()

static implicit Ext.Net.JsonPProxy.operator JsonPProxy ( JsonPProxy.Config  config)
inlinestatic

◆ ToBuilder()

JsonPProxy.Builder Ext.Net.JsonPProxy.ToBuilder ( )
inline

◆ ToNativeBuilder()

override IControlBuilder Ext.Net.JsonPProxy.ToNativeBuilder ( )
inlinevirtual

Reimplemented from Ext.Net.BaseItem.

Property Documentation

◆ AutoAppendParams

virtual bool Ext.Net.JsonPProxy.AutoAppendParams
getset

True to automatically append the request's params to the generated url. Defaults to true

◆ CallbackKey

virtual string Ext.Net.JsonPProxy.CallbackKey
getset

Specifies the GET parameter that will be sent to the server containing the function name to be executed when the request completes. Defaults to callback. Thus, a common request will be in the form of url?callback=Ext.data.JsonP.callback1

◆ ConfigOptions

override ConfigOptionsCollection Ext.Net.JsonPProxy.ConfigOptions
get

◆ InstanceOf

override string Ext.Net.JsonPProxy.InstanceOf
get

◆ RecordParam

virtual string Ext.Net.JsonPProxy.RecordParam
getset

The param name to use when passing records to the server (e.g. 'records=someEncodedRecordString'). Defaults to 'records'

◆ Type

override string Ext.Net.JsonPProxy.Type
getprotected

Alias


The documentation for this class was generated from the following files: