Search code examples
jquerysettimeoutreload

adding a delay to page refresh so success message is displayed longer


I have a form that is done in a lightbox, once it is submitted successfully it displays a success message, and will then reload the page. how do I delay the page reload so the user has some time to see the message? with the code below, the delay happens once the button is hit and it gets hung up and displays a "mail:Could not instantiate mail function."

if(data.result == 'success')
    {   
        $('form#car-inquiry').siblings('#form-welcome').hide();
        $('form#car-inquiry').hide();
        $('#success_message').show();
        $('#error_message').hide();
        setTimeout(function(){
        location.reload(true);}, 5000);
    }

Solution

  • try like this in your script

    if(data.result == 'success')
     {   
      setTimeout(function () {
         $('form#car-inquiry').siblings('#form-welcome').hide();
         $('form#car-inquiry').hide();
         $('#success_message').show();
         $('#error_message').hide();
                 }, 1000);
      setTimeout(function () {
                location.reload(true);
                 }, 1500);
     }