Removing the Ajax loader image after a while

I have an ajax loader that pops up after clicking a button with the following code:

jQuery(document).ready(function($){
{
        $.getElementById('form').onsubmit = function () {
        $.getElementById('submit').style.display = 'block';
        $.getElementById('loading2').style.display = 'block';
        };
    }(document));
});

      

HTML:

 <input type="submit" class="button alt"  onclick="$(\'#loading\').show();" name="woocommerce_checkout_place_order"/>' 

      

I would like the ajax loader to disappear after 10 seconds.

Please let me know

+3


source to share


2 answers


You can use this to hide your bootloader after 10 seconds.

setTimeout(function() {
    $('#loading').hide(); // I wasnt sure which one you wanted to hide
    $('#loading2').hide();
}, 10000);

      



Also looking at your code, I'm not sure if this would work. Also if you are using jQuery you don't really need to use vanilla Javascript for your code to be modified.

jQuery(document).ready(function($){
    $('#form').submit(function () {
        $('#submit').css('display', 'block');
        $('#loading2').css('display', 'block');
    });
});

      

+1


source


$(function() {
// setTimeout() function will be fired after page is loaded
// it will wait for 10 sec. and then will fire
// $("#successMessage").hide() function

setTimeout(function() {
$("#loading").hide('blind', {}, 500)
}, 10000);
});

      

Note. ... For jQuery function to work inside setTimeout you have to wrap it inside



function() { ... }

      

0


source







All Articles