X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..2e847cf21b8ab9d15fa167b315ca5b2fa92638fc:/src/data/ScriptTagProxy.js diff --git a/src/data/ScriptTagProxy.js b/src/data/ScriptTagProxy.js index b44d3553..ea7c0368 100644 --- a/src/data/ScriptTagProxy.js +++ b/src/data/ScriptTagProxy.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.0 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.1.1 + * Copyright(c) 2006-2010 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ @@ -38,6 +38,32 @@ 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);
 
* * @constructor @@ -108,7 +134,7 @@ Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, { *
  • The "arg" argument from the load function
  • *
  • A boolean success indicator
  • * - * @param {Object} scope The scope in which to call the callback + * @param {Object} scope The scope (this reference) in which the callback function is executed. Defaults to the browser window. * @param {Object} arg An optional argument which is passed to the callback as its second parameter. */ doRequest : function(action, rs, params, reader, callback, scope, arg) { @@ -171,7 +197,7 @@ Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, { * @param {String} action [Ext.data.Api.actions.create|read|update|destroy] * @param {Object} trans The request transaction object * @param {Object} res The server response - * @private + * @protected */ onRead : function(action, trans, res) { var result; @@ -200,25 +226,25 @@ Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, { * @param {String} action [Ext.data.Api.actions.create|read|update|destroy] * @param {Object} trans The request transaction object * @param {Object} res The server response - * @private + * @protected */ - onWrite : function(action, trans, res, rs) { + onWrite : function(action, trans, response, rs) { var reader = trans.reader; try { // though we already have a response object here in STP, run through readResponse to catch any meta-data exceptions. - reader.readResponse(action, res); + var res = reader.readResponse(action, response); } catch (e) { this.fireEvent('exception', this, 'response', action, trans, res, e); trans.callback.call(trans.scope||window, null, res, false); return; } - if(!res[reader.meta.successProperty] === true){ + if(!res.success === true){ this.fireEvent('exception', this, 'remote', action, trans, res, rs); trans.callback.call(trans.scope||window, null, res, false); return; } - this.fireEvent("write", this, action, res[reader.meta.root], res, rs, trans.arg ); - trans.callback.call(trans.scope||window, res[reader.meta.root], res, true); + this.fireEvent("write", this, action, res.data, res, rs, trans.arg ); + trans.callback.call(trans.scope||window, res.data, res, true); }, // private