简体   繁体   中英

How to reload a webpage after user clicks back button from previous page?

I am trying to submit a form. When i click the the submit button it takes me to the next page which is not in my control(hitting an api). From that, that page user can click browsers back button come to my form page. From there onwards user can fill the form and resubmit. In this form i am passing an randomid as a hidden value. Problem is even when user comes back by clicking back button and resubmit the form with different values and that randomid remains the same. How can i solve this?

Here is my form.php

<?php
include_once 'dbconnect.php';

$r= mt_rand();

<body>
<form id="register-form" action="http://api.ipayy.com/v001/c/oc/dopayment" method="get" class="form input-group register-form">
         <div class="container-fluid">
            <div class="row">

                <input type="hidden" id="reqnum" name="reqnum"  value="<?php echo $r ?>" />

                <div class="col-sm-3 col-xs-12">
                    <input name="fname" id="fname" class="form-cus form-control" type="text" placeholder="Your First Name"  autocomplete="off"  required>
</div>

<div class="col-sm-3 col-xs-12">
                    <input name="title" id="title" class="form-cus form-control" type="text" placeholder="Title of Your Web site" autocomplete="off" required>
                </div>

                <div class="col-sm-3 col-xs-12">
                    <input name="descr" id="descr" class="form-cus form-control" type="text" placeholder="Description of Your Web site" autocomplete="off" required>
                </div>

                <div class="form-group col-sm-3 col-xs-12">
                    <button class="btn btn-1 btn-fill" type="submit" id="btn-signup" name="btn-signup" style="display:none;">Submit</button>
                </div>

            </div> 
        </div> 
    </form>
<script>
$('form').submit(function() {
    $.ajax({

        url: "http://ll.php",
        async:false,
        data: $(this).serialize(),
        success: function(data){

        },
        error : function(data) {
            console.log(data);
        }
    });

});
</script> 

Update, here's another solution that I've come across...

function Reload() {
    try {
        var headElement = document.getElementsByTagName("head")[0];

        if (headElement && headElement.innerHTML)
             headElement.innerHTML += "<meta http-equiv=\"refresh\" content=\"1\">";
    }
    catch (e) {}
}

window.onload(function () { Reload(); }

By default, a browser will show a cached version of the previous page.

To get around this, it's a very simple fix...

<body onunload="">

This will disable the browser from caching the page and force it to reload the page when a user clicks "back"

You should use ajax post form submit. You can use event.preventDefault(); to prevent default form submit. I think it good solution to avoid unwanted page redirect or page reload

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM