*/
_suppressErrors: false,
+ /**
+ * last request
+ * @var jqXHR
+ */
+ _lastRequest: null,
+
/**
* Initializes AJAXProxy.
*
success: null,
suppressErrors: false,
type: 'POST',
- url: 'index.php/AJAXProxy/?t=' + SECURITY_TOKEN + SID_ARG_2ND
+ url: 'index.php/AJAXProxy/?t=' + SECURITY_TOKEN + SID_ARG_2ND,
+ aborted: null,
+ autoAbortPrevious: false
}, options);
this.confirmationDialog = null;
/**
* Sends an AJAX request.
+ *
+ * @param abortPrevious boolean
+ * @return jqXHR
*/
- sendRequest: function() {
+ sendRequest: function(abortPrevious) {
this._init();
- $.ajax({
+ if (abortPrevious || this.options.autoAbortPrevious) {
+ this.abortPrevious();
+ }
+
+ this._lastRequest = $.ajax({
data: this.options.data,
dataType: this.options.dataType,
jsonp: this.options.jsonp,
success: $.proxy(this._success, this),
error: $.proxy(this._failure, this)
});
+ return this._lastRequest;
+ },
+
+ /**
+ * Aborts the previous request
+ */
+ abortPrevious: function() {
+ if (this._lastRequest !== null) {
+ this._lastRequest.abort();
+ }
},
/**
* @param string errorThrown
*/
_failure: function(jqXHR, textStatus, errorThrown) {
+ if (textStatus == 'abort') {
+ // call child method if applicable
+ if ($.isFunction(this.options.aborted)) {
+ this.options.aborted(jqXHR);
+ }
+
+ return;
+ }
+
try {
var $data = $.parseJSON(jqXHR.responseText);
* Fires after an AJAX request, hides global loading status.
*/
_after: function() {
+ this._lastRequest = null;
if ($.isFunction(this.options.after)) {
this.options.after();
}