I have a collapsible element wherein an ajax is requested when the collapsible is opened. However, I also want to stop the ajax request before the collapsible is closed.
$(".collapse").on('show.bs.collapse', function(e) {
$.ajax
({
type: "GET",
url: "check_active_operator.php",
cache: false,
success: function(r)
{
if(r==1){
//Operator is available
}else if(r==0){
//No operator available
}
}
});
});
$(".collapse").on('hide.bs.collapse', function(e) {
// STOP AJAX REQUEST
});
NOTE: I also have this ajax request on check_active_operator.php. That request must be aborted as well if the collapsible is closed. As of now, it is still running when the collapsible is closed.
function getMessages(){
var getchatroomid = $.trim($("#chatroomid").val());
$.ajax
({
type: "POST",
url: "messages.php",
data: {getchatroomid},
cache: false,
success: function(data)
{
$(".chatMessages").html(data);
}
});
}
setInterval(function(){
getMessages();
var c = $('.chatMessages');
c.scrollTop(c.prop("scrollHeight")); //scroll down
}, 1000); //half a second