Basically I want to show a loading gif...
here's the code I'm using:
$("#mail-change input[type=submit]").click(function(event){
$.post('user_settings.php', $("#mail-change").serialize(), function(res) {
$(res).insertBefore(".grey");
}, 'html')
});
The ajaxStart() method specifies a function to be run when an AJAX request starts. Note: As of jQuery version 1.8, this method should only be attached to document.
The ajaxComplete() method specifies a function to be run when an AJAX request completes. Note: As of jQuery version 1.8, this method should only be attached to document. Unlike ajaxSuccess(), functions specified with the ajaxComplete() method will run when the request is completed, even it is not successful.
Definition and Usage. The ajaxSetup() method sets default values for future AJAX requests.
The ajaxStart and ajaxStop events are events that relate to all Ajax requests together. ajaxStart (Global Event) This event is triggered if an Ajax request is started and no other Ajax requests are currently running.
$("#loading").ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
EDIT:
$("#mail-change input[type=submit]").click(function(event){
$("#loading").show()
$.post('user_settings.php', $("#mail-change").serialize(), function(res) {
$(res).insertBefore(".grey");
$("#loading").hide();
}, 'html');
});
or:
$.ajax({
url : 'user_settings.php',
data: $("#mail-change").serialize(),
beforeSend: function(){
$("#loading").show();
},
complete: function(){
$("#loading").hide();
},
success: function(res) {
$(res).insertBefore(".grey");
}
});
See:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With