AJAX reload page with POST

前端 未结 4 1849
眼角桃花
眼角桃花 2020-12-18 20:20

Can anybody tell me how to refresh the current page with JavaScript, having a POST variable modified or added?

To be clear, I want to set some POST variables prior t

相关标签:
4条回答
  • 2020-12-18 20:22

    By using jquery ajax you can reload your page

    $.ajax({
        type: "POST",
        url: "packtypeAdd.php",
        data: infoPO,
        success: function() {   
            location.reload();  
        }
    });
    
    0 讨论(0)
  • 2020-12-18 20:25

    If you want to refresh the entire page, it makes no sense to use AJAX. Use normal Javascript to post the form element in that page. Make sure the form submits to the same page, or that the form submits to a page which then redirects back to that page

    Javascript to be used (always in myForm.php):

    function submitform()
    {
      document.getElementById('myForm').submit();
    }
    

    Suppose your form is on myForm.php: Method 1:

    <form action="./myForm.php" method="post" id="myForm">
        ...
    </form>
    

    Method 2:

    myForm.php:

    <form action="./myFormActor.php" method="post" id="myForm">
        ...
    </form>
    

    myFormActor.php:

    <?php
        //all code here, no output
        header("Location: ./myForm.php");
    ?>
    
    0 讨论(0)
  • 2020-12-18 20:27

    Reload the current document:

     <script type="text/javascript">
     function reloadPage()
     {
       window.location.reload()
     }
     </script>
    
    0 讨论(0)
  • 2020-12-18 20:30

    There's another way with post instead of ajax

    var jqxhr = $.post( "example.php", function() {
      alert( "success" );
    })
      .done(function() {
        alert( "second success" );
      })
      .fail(function() {
        alert( "error" );
      })
      .always(function() {
        alert( "finished" );
      });
    
    0 讨论(0)
提交回复
热议问题