A function to execute when the request
+ *
callback : Function (Optional) A function to execute when the request
* completes, whether it is a success or failure.
*
scope : Object (Optional)The scope in
* which to execute the callbacks: The "this" object for the callback function. Defaults to the browser window.
@@ -91,32 +90,33 @@ Ext.define('Ext.data.JsonP', {
*/
request: function(options){
options = Ext.apply({}, options);
-
+
//
if (!options.url) {
Ext.Error.raise('A url must be specified for a JSONP request.');
}
//
-
- var me = this,
- disableCaching = Ext.isDefined(options.disableCaching) ? options.disableCaching : me.disableCaching,
- cacheParam = options.disableCachingParam || me.disableCachingParam,
- id = ++me.statics().requestCount,
- callbackName = options.callbackName || 'callback' + id,
- callbackKey = options.callbackKey || me.callbackKey,
- timeout = Ext.isDefined(options.timeout) ? options.timeout : me.timeout,
- params = Ext.apply({}, options.params),
+
+ var me = this,
+ disableCaching = Ext.isDefined(options.disableCaching) ? options.disableCaching : me.disableCaching,
+ cacheParam = options.disableCachingParam || me.disableCachingParam,
+ id = ++me.statics().requestCount,
+ callbackName = options.callbackName || 'callback' + id,
+ callbackKey = options.callbackKey || me.callbackKey,
+ timeout = Ext.isDefined(options.timeout) ? options.timeout : me.timeout,
+ params = Ext.apply({}, options.params),
url = options.url,
- request,
+ name = Ext.isSandboxed ? Ext.getUniqueGlobalNamespace() : 'Ext',
+ request,
script;
-
- params[callbackKey] = 'Ext.data.JsonP.' + callbackName;
+
+ params[callbackKey] = name + '.data.JsonP.' + callbackName;
if (disableCaching) {
params[cacheParam] = new Date().getTime();
}
-
+
script = me.createScript(url, params);
-
+
me.statics().requests[id] = request = {
url: url,
params: params,
@@ -128,17 +128,17 @@ Ext.define('Ext.data.JsonP', {
callback: options.callback,
callbackName: callbackName
};
-
+
if (timeout > 0) {
request.timeout = setTimeout(Ext.bind(me.handleTimeout, me, [request]), timeout);
}
-
+
me.setupErrorHandling(request);
me[callbackName] = Ext.bind(me.handleResponse, me, [request], true);
Ext.getHead().appendChild(script);
return request;
},
-
+
/**
* Abort a request. If the request parameter is not specified all open requests will
* be aborted.
@@ -147,7 +147,7 @@ Ext.define('Ext.data.JsonP', {
abort: function(request){
var requests = this.statics().requests,
key;
-
+
if (request) {
if (!request.id) {
request = requests[request];
@@ -161,7 +161,7 @@ Ext.define('Ext.data.JsonP', {
}
}
},
-
+
/**
* Sets up error handling for the script
* @private
@@ -170,7 +170,7 @@ Ext.define('Ext.data.JsonP', {
setupErrorHandling: function(request){
request.script.onerror = Ext.bind(this.handleError, this, [request]);
},
-
+
/**
* Handles any aborts when loading the script
* @private
@@ -180,7 +180,7 @@ Ext.define('Ext.data.JsonP', {
request.errorType = 'abort';
this.handleResponse(null, request);
},
-
+
/**
* Handles any script errors when loading the script
* @private
@@ -190,7 +190,7 @@ Ext.define('Ext.data.JsonP', {
request.errorType = 'error';
this.handleResponse(null, request);
},
-
+
/**
* Cleans up anu script handling errors
* @private
@@ -199,7 +199,7 @@ Ext.define('Ext.data.JsonP', {
cleanupErrorHandling: function(request){
request.script.onerror = null;
},
-
+
/**
* Handle any script timeouts
* @private
@@ -209,7 +209,7 @@ Ext.define('Ext.data.JsonP', {
request.errorType = 'timeout';
this.handleResponse(null, request);
},
-
+
/**
* Handle a successful response
* @private
@@ -217,9 +217,9 @@ Ext.define('Ext.data.JsonP', {
* @param {Object} request The request
*/
handleResponse: function(result, request){
-
+
var success = true;
-
+
if (request.timeout) {
clearTimeout(request.timeout);
}
@@ -227,7 +227,7 @@ Ext.define('Ext.data.JsonP', {
delete this.statics()[request.id];
this.cleanupErrorHandling(request);
Ext.fly(request.script).remove();
-
+
if (request.errorType) {
success = false;
Ext.callback(request.failure, request.scope, [request.errorType]);
@@ -236,7 +236,7 @@ Ext.define('Ext.data.JsonP', {
}
Ext.callback(request.callback, request.scope, [success, result, request.errorType]);
},
-
+
/**
* Create the script tag
* @private