search

Home  >  Q&A  >  body text

javascript - The page returns to the previous level and the processed data is returned repeatedly?

There is a function on the homepage of the mall, that is, when a user logs in for the first time that day, a [Points + 10] prompt will be given to the user on the homepage

Describe how the bug occurred:
When I logged in for the first time that day, a prompt of [Points +10] popped up. Then at this time, I clicked on any link on the homepage and clicked on that link. When returning, when I return to the homepage, the prompt [Points +10] will still appear repeatedly.

But it shouldn’t be, because I already have logic processing in the background. When the user logs in for the first time that day, a record is inserted into the table and 200 is returned. If the user has already logged in, 202 is returned. , the front desk prompts based on the return status code, but when returns to the homepage from the previous page, there will still be a prompt. If I refresh the homepage again, the prompt will disappear

I compared it twice (The page just entered and The page returned from the previous level) and the results returned by the url were both 200, this is very strange

Post the code:
js

< /p>

php

< /p>

Please help~


Get requests will be cached by the browser, orz~

ringa_leeringa_lee2848 days ago362

reply all(3)I'll reply

  • 迷茫

    迷茫2017-05-16 13:09:04

    <?php
    session_start();
    if ($_POST){
        if(!$_SESSION['status2']){
            echo 1;
        $_SESSION['status2']=1;
        } else {
            echo 2;
        }
    }
    
    <script>
      $.post('./test.php',{statue:1},function(e){
        alert(e);
      })
    </script>
    

    After testing it like this, I found that there is no problem. It is recommended that you trace the code to determine whether you have logged in. Is there any cache or other factors that may affect it?

    reply
    0
  • 高洛峰

    高洛峰2017-05-16 13:09:04

    Is there any problem with the login status judgment of total?

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 13:09:04

    Consider whether it is the impact of caching.
    Check to see if the points have indeed increased twice in the background. If it does not increase the second time, it means that your background logic is correct, and it may be caused by browser cache. If the background is indeed increased, then the background logic is wrong.

    reply
    0
  • Cancelreply