Before AJAX method I add a GIF image but duration of loading time is very short. How can I set time of loading duration and after that AJAX response will show?
$('.signup p').html('<img src="img/loading.gif" width="40px" height="40px" alt="loading_effect" />');
$.ajax({
url : 'signup_action.php',
method : 'post',
data : {name,email,password1,dob,gender},
success : function(response){
$('.signup p').html(response);
}
});
Here is exactly how you can delay it like this way as :
BY USING .delay()
:
$('.signup p').delay(800).html('<img src="img/loading.gif" width="40px" height="40px" alt="loading_effect" />');
Note : You need to enter the seconds in miliseconds like this way as i.e for 1 Second you will need 1000.
Reference URL For .delay()
:
OR
Ofcourse another way to do this is as :
$(document).ajaxStart(function() {
$('.signup p').show();
}).ajaxStop(function() {
$('.signup p').hide();
});
Reference Links :
.ajaxStart()
: https://api.jquery.com/ajaxStart/
.ajaxStop()
: https://api.jquery.com/ajaxStop/