I think you run those json requeston top of the object XMLHttpRequestor, in other words, use .ajax(). You can generally cancel the ajax request using .abort().
var xhr = $.ajax({});
if(xhr)
xhr.abort();
since it .ajax()returns the original event XHRthat you can save in this place and abort this request. Of course, you would need to create some of the “query logic” to process this material. Example:
var xhrmanager = function() {
var requests = [],
self = {};
self.create = function(params, cb){
if(typeof params === 'object') {
var xhr = $.ajax($.extend({
url: '/path/script.pl',
dataType: 'json',
type: 'GET',
success: function(data, status, req){
if(typeof cb === 'function')
cb.apply(this, [data]);
},
complete: function(req, status) {
var pos = $.inArray(req, requests);
if(pos > -1)
requests.splice(pos, 1)
}
}, params || {}));
}
};
self.clearAll = function(){
for(var i = 0, len = requests.length; i < len; i++){
requests[i].abort();
}
};
return self;
};
:
var json_requests = xhrmanager();
json_requests.create({
data: 'some=data'
}, function(data) {
});
json_requests.clearAll();