Search code examples
phpajaxformssubmitpage-refresh

Ajax Form Submit & Refresh Page Out of DIV


I'm using ajax form submit script like

    <script type="text/javascript">  
  $(document).ready(function(){  
    $("#login").submit(function(event) {  

        /* stop form from submitting normally */  
        event.preventDefault();   

        $.post( 'login.php', $("#login").serialize(),  
          function( data ) {  
              $("#loginoutput").append(data);  
          }  
        );  
      });  
  });  
</script> 
. . .

When form submitted all content shown in loginoutput DIV. Errors, controls and success messages etc. But I want to redirect home page after submit with success but redirection done in DIV section. I want to refresh whole page not in DIV section. But all redirections doing in DIV like output messages.

How can I refresh whole page after form submit?

Regards


Solution

  • If you want to refresh the screen after an successful ajax post. Then just refresh the screen in the success function of the ajax call like this:

    $.post( 'login.php', 
        $("#login").serialize(),
        function(data) { // will trigger after successful request (HTTP 200)
            document.location.reload(true);
        }
    };