Thanks ,
Rubens
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:
Consider the following code :
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(");");
}
RecordDef recordDef = new RecordDef(new FieldDef[]{
new StringFieldDef("name", "name"), // "mapping" property not needed if it's the same as "name"
new StringFieldDef("occupation") // this field will use "occupation" as the mapping.
});
JsonReader reader = new JsonReader(new JsonReaderConfig() {
{
setTotalProperty("results"); // The property which contains the total dataset size (optional)
setRoot("rows"); // The property which contains an Array of row objects
setId("id"); // The property within each row object that provides an ID for the record (optional)
}}, recordDef);
If the data is being server from the same domain, then you don;t need to use ScriptTagProxy but instead need to use
HttpProxy pointing to the URL that returns data in the following format :
{ 'results': 2, 'rows': [
{ 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
{ 'id'
: 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
}
However if this data is being read from another domain, a couple of things need to be done.Now bar.php cannot return standard Json like the one above when using HttpProxy. Instead it needs to wrap the Json data in a callback. This is required when reading data from antoher domain. When the ScriptTagProxy tries for fetch data, it will issue an HTTP request to the specified URL passing the name of the callback function that it needs the results to be wrapped in. For example http://externalurl:8023/foo/bar.php?start=0&limit=25&sort=nome&dir=DESC&_dc=1196661274168& callback=stcCallback1002
ScriptTagProxy proxy = new ScriptTagProxy("http://externalurl:8023/foo/bar.php");
stcCallback1002({ 'results': 2, 'rows': [
{ 'id': 1, 'name': 'Bill', occupation: 'Gardener'
},
{ 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' }]);
}
ScriptTagProxy(String, int, String).