Store the jQuery jqXHR request object in the json_request, and return it from sendRequest() so caller can access it, if needed.

This commit is contained in:
Nathan Gray 2014-03-26 17:53:09 +00:00
parent a1bd074787
commit e7fd500006

View File

@ -70,6 +70,8 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
* Sends the assembled request to the server * Sends the assembled request to the server
* @param {boolean} [async=false] Overrides async provided in constructor to give an easy way to make simple async requests * @param {boolean} [async=false] Overrides async provided in constructor to give an easy way to make simple async requests
* @param {string} method='POST' allow to eg. use a (cachable) 'GET' request instead of POST * @param {string} method='POST' allow to eg. use a (cachable) 'GET' request instead of POST
*
* @return {jqXHR} jQuery jqXHR request object
*/ */
json_request.prototype.sendRequest = function(async,method) { json_request.prototype.sendRequest = function(async,method) {
if(typeof async != "undefined") if(typeof async != "undefined")
@ -89,7 +91,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
// Send the request via AJAX using the jquery ajax function // Send the request via AJAX using the jquery ajax function
// we need to use jQuery of window of egw object, as otherwise the one from main window is used! // we need to use jQuery of window of egw object, as otherwise the one from main window is used!
// (causing eg. apply from server with app.$app.method to run in main window instead of popup) // (causing eg. apply from server with app.$app.method to run in main window instead of popup)
(this.egw.window?this.egw.window.$j:$j).ajax({ this.request = (this.egw.window?this.egw.window.$j:$j).ajax({
url: this.url, url: this.url,
async: this.async, async: this.async,
context: this, context: this,
@ -98,10 +100,15 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
type: method || 'POST', type: method || 'POST',
success: this.handleResponse, success: this.handleResponse,
error: function(_xmlhttp, _err) { error: function(_xmlhttp, _err) {
this.egw.debug('error', 'Ajax request to', this.url, ' failed:', // Don't error about an abort
_err); if(_err !== 'abort')
{
this.egw.debug('error', 'Ajax request to', this.url, ' failed:', _err);
}
} }
}); });
return this.request;
} }
json_request.prototype.handleResponse = function(data) { json_request.prototype.handleResponse = function(data) {
@ -167,6 +174,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
this.callback.call(this.context,res); this.callback.call(this.context,res);
} }
} }
this.request = null;
} }
var json = { var json = {