Deadweight
09-12-2017, 03:33 PM
Currently, I have a class set up in Ajax that calls certain pages.
I have a page that has a 5-second sleep to it (because I was checking something); however, the issue is if that page is still getting called I want to cancel and stop the 5-second page call (or any page for that matter) and start the other ajax call.
The set up:
var polling = {
add : function(name, obj) {
this[name] = new ajax(obj);
return this;
}
};
var timeout;
function ajax(options) {
var instance = $(this);
var consti = {
url: path + 'sniffer.php',
complete: function() {request = null;console.log(request);}
};
var defaults = {
method: 'POST',
data: {},
dataType: 'json',
cache: 'false',
async: true,
success: function(reply) {console.log(reply);},
error: function(jqXHR, textStatus, errorThrown){
if(textStatus == 'abort') return;
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
};
var settings = $.extend({}, defaults, options, consti);
var request = null;
function runAjax() {
if ( request != null && request.readyState != 4 ) {
console.log('Should Abort');
request.abort();
request = null;
}
console.log(request);
request = $.ajax(settings);
console.log(request);
}
this.set = function(options) {
settings = $.extend({}, defaults, settings, options, consti);
};
this.get = function() {
return settings;
};
this.run = function() {
if ( settings.url != null ) {
runAjax();
} else {
console.log('Ajax Error: Page is null.');
}
};
}
polling.add('onclick');
The call:
polling.onclick.run();
sniffer.php will auto detect the page that is required to load.
Any suggestions to cancel and abort the 5-second sleep in a page would be awesome. Thanks.
I have a page that has a 5-second sleep to it (because I was checking something); however, the issue is if that page is still getting called I want to cancel and stop the 5-second page call (or any page for that matter) and start the other ajax call.
The set up:
var polling = {
add : function(name, obj) {
this[name] = new ajax(obj);
return this;
}
};
var timeout;
function ajax(options) {
var instance = $(this);
var consti = {
url: path + 'sniffer.php',
complete: function() {request = null;console.log(request);}
};
var defaults = {
method: 'POST',
data: {},
dataType: 'json',
cache: 'false',
async: true,
success: function(reply) {console.log(reply);},
error: function(jqXHR, textStatus, errorThrown){
if(textStatus == 'abort') return;
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
};
var settings = $.extend({}, defaults, options, consti);
var request = null;
function runAjax() {
if ( request != null && request.readyState != 4 ) {
console.log('Should Abort');
request.abort();
request = null;
}
console.log(request);
request = $.ajax(settings);
console.log(request);
}
this.set = function(options) {
settings = $.extend({}, defaults, settings, options, consti);
};
this.get = function() {
return settings;
};
this.run = function() {
if ( settings.url != null ) {
runAjax();
} else {
console.log('Ajax Error: Page is null.');
}
};
}
polling.add('onclick');
The call:
polling.onclick.run();
sniffer.php will auto detect the page that is required to load.
Any suggestions to cancel and abort the 5-second sleep in a page would be awesome. Thanks.