- Implement request.abort() to cancel a request

- Check that the response is there before trying to access a key inside it
- Don't return null for encoding 0
This commit is contained in:
Nathan Gray 2010-08-10 14:58:54 +00:00
parent 7ea2ef612c
commit 8728ba5512

View File

@ -80,7 +80,7 @@ function _egw_json_encode_simple(input)
function egw_json_encode(input) function egw_json_encode(input)
{ {
if (!input) return 'null'; if (input == null || !input && input.length == 0) return 'null';
var simple_res = _egw_json_encode_simple(input); var simple_res = _egw_json_encode_simple(input);
if (simple_res == null) if (simple_res == null)
@ -197,6 +197,7 @@ function egw_json_request(_menuaction, _parameters, _context)
this.url = url + '/json.php'; this.url = url + '/json.php';
this.request = null;
this.sender = null; this.sender = null;
this.callback = null; this.callback = null;
this.alertHandler = this.alertFunc; this.alertHandler = this.alertFunc;
@ -237,7 +238,7 @@ egw_json_request.prototype.sendRequest = function(_async, _callback, _sender)
}; };
//Send the request via the jquery AJAX interface to the server //Send the request via the jquery AJAX interface to the server
$.ajax({url: this.url + '?menuaction=' + this.menuaction, this.request = $.ajax({url: this.url + '?menuaction=' + this.menuaction,
async: is_async, async: is_async,
context: this, context: this,
data: request_obj, data: request_obj,
@ -248,6 +249,11 @@ egw_json_request.prototype.sendRequest = function(_async, _callback, _sender)
}); });
} }
egw_json_request.prototype.abort = function()
{
this.request.abort();
}
egw_json_request.prototype.alertFunc = function(_message, _details) egw_json_request.prototype.alertFunc = function(_message, _details)
{ {
alert(_message); alert(_message);
@ -350,7 +356,7 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
} }
catch (e) catch (e)
{ {
_egw_json_debug_log(e); _egw_json_debug_log(e, {'Function': res.data.func, 'Parameters': res.data.params});
} }
hasResponse = true; hasResponse = true;
} else } else
@ -477,7 +483,7 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
} }
/* If no explicit response has been specified, call the callback (if one was set) */ /* If no explicit response has been specified, call the callback (if one was set) */
if (!hasResponse && this.callback) if (!hasResponse && this.callback && data.response[i])
{ {
this.callback.call(this.sender, data.response[i].data); this.callback.call(this.sender, data.response[i].data);
} }