I have 2 functions, submit() with $.ajax and click() with $.post. In the function with $.ajax I use ajaxStart() and ajaxStop(), but at $.post no. Example:
In submit:
$(document).ready(function(){
$('#myform').submit(function() {
$(this).ajaxStart(function() {
$('.notice').html('Send...');
$('#send').attr('disabled', 'disabled');
});
$(this).ajaxComplete(function() {
$('#send').removeAttr('disabled');
});
$.ajax({
type: "POST",
url: 'server01.php',
data: $(this).serialize(),
success: function(data) {
switch(data){
case 'success':
$('.notice').html('Good!');
setTimeout("location.reload();",3000);
break;
default:
$('.notice').html('Error');
break;
}
} });
return false;
});
});
In click:
$(function() {
$('#language').click( function() {
$.post("language.php", { language: $(this).attr('class') } )
.success(function(data) { location.reload(); })
.error(function() { alert("error"); });
return false;
});
});
The problem is that when I run the click() function activates the ajaxStart() method on submit event.
There is a possibility to disable ajaxStart() or not to run when I use the click function?
I don’t think there is a possibility to disable ajaxStart(), because it works globally for the whole code.
but if you want to isolate what you coded for your myform element, you can do something like this :