Jump to content

Recommended Posts

My application requires the page to reload alot to trigger all of the functions that calculate price and i am now starting to see the following message alot.

To display this page, Firefox Developer Edition must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.

I know that i can use AJAX to only reload sections that i have changed, but in effect i am changing so much of the page that i felt it more simple to reload the page.

Is there a simple but 'professional' way that i can prevent this message and prevent things being added to the database more than once when a reload is required?

Send a location header to same page so it reload without the posted data

 

myscript.php:

if ($_SERVER['REQUEST_METHOD']=='POST')  {
    
    // validate POST data
    
    if (no errors)  {
        
        // update database
        
        header("Location: myscript.php");
        exit;
    }
}

// build page content

 

The URLs has got quite a lot of params in them.

 

Would

header("Refresh:0");

yield the same result?

 

This is currently how i am doing everything:

function applyDiscountToAllDiscountableQuoteItems($quoteId, $discountPercentage) {
                $remainingPercentage = 100 - $discountPercentage
                $.ajax({

                    type: 'post',
                    data: {
                        'ajax': 'applyDiscountToAllDiscountableQuoteItems',
                        'quoteId': $quoteId,
                        'discountPercentage': $discountPercentage,
                        'remainingPercentage': $remainingPercentage
                    },
                    success: function(resp) {
                        location.reload();
                    }
                })
            }

            function setNewItemPrice($newPrice, $itemId) {
                $.ajax({
                    type: 'post',
                    data: {
                        'ajax': 'setNewItemPrice',
                        'quoteId': $quoteId,
                        'newPrice': $newPrice,
                        'itemId': $itemId
                    },
                    success: function(resp) {
                        // location.reload();
                    }
                })
            }

 

Edited by Adamhumbug
11 hours ago, Barand said:

Send a location header to same page so it reload without the posted data

 

myscript.php:

if ($_SERVER['REQUEST_METHOD']=='POST')  {
    
    // validate POST data
    
    if (no errors)  {
        
        // update database
        
        header("Location: myscript.php");
        exit;
    }
}

// build page content

 

So in one of my function (in functions.php file) that is called with ajax from other page i should put

header("Location: functions.php");

 

the message you cited occurs when you do a 'view source' of the page in the browser. any get parameters you have in the URL should only determine what content is gotten and displayed on the page, not what post method form action is performed in the server-side code. if the last request the browser has for a URL is a html post method form submission, the form data will get resubmitted when you do a 'view source' of the page (even if you have prevented the form itself from being redisplayed on that page.)

your first post in this thread indicated that you know you could use ajax, not that you were already using it. the reply you got is based on how you would normally do this, using a html post method form submitted to server-side post method form processing code, on the same page, to prevent the browser from trying to resubmit the post method form data should that page get reloaded, a 'view source' performed on it, or the URL is browsed away from and back to, by instructing the browser to perform a get request for the exact (including any existing get parameters) same URL of the current page.

the main point of using ajax on a web page is so that you don't reload the whole page. if what you are doing means that you are going to reload the whole page anyways, you shouldn't be using ajax to do this. when you do use ajax to submit a post method form, the ajax response code needs to deal with any server-side success/failure response (validation errors, duplicate data errors, ...) that are produced and output by the server-side code.

 

 

Edited by mac_gyver
On 10/22/2023 at 3:28 PM, mac_gyver said:

the message you cited occurs when you do a 'view source' of the page in the browser. any get parameters you have in the URL should only determine what content is gotten and displayed on the page, not what post method form action is performed in the server-side code. if the last request the browser has for a URL is a html post method form submission, the form data will get resubmitted when you do a 'view source' of the page (even if you have prevented the form itself from being redisplayed on that page.)

your first post in this thread indicated that you know you could use ajax, not that you were already using it. the reply you got is based on how you would normally do this, using a html post method form submitted to server-side post method form processing code, on the same page, to prevent the browser from trying to resubmit the post method form data should that page get reloaded, a 'view source' performed on it, or the URL is browsed away from and back to, by instructing the browser to perform a get request for the exact (including any existing get parameters) same URL of the current page.

the main point of using ajax on a web page is so that you don't reload the whole page. if what you are doing means that you are going to reload the whole page anyways, you shouldn't be using ajax to do this. when you do use ajax to submit a post method form, the ajax response code needs to deal with any server-side success/failure response (validation errors, duplicate data errors, ...) that are produced and output by the server-side code.

 

 

So this should only be happening becuase i have inspector open at the same time?

 

I will do some testing around this.

 

I have noted your other comments, which i will come back to.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.