Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:15:33+00:00 2026-05-24T06:15:33+00:00

Hi I have got an ajax code as follows: $.ajax({ type:POST, url: ‘sample.php’, data:data=+data,

  • 0

Hi I have got an ajax code as follows:

$.ajax({
                type:"POST",
                url: 'sample.php',
                data:"data="+data,
                success: function(server_response) { 
                $('.functions').ajaxComplete(function(event, request){

                  if(server_response == 0)
                     {
                                showmsg('An email with instructions to reset password has been sent to your email address. Please check it.');
                     }
                  else if(server_response == 1)
                    {
                                showmsg('Email address was not found in our database. Please enter a valid email address');
                    }
                  else
                    {
                                showmsg('Some problem occured while sending you an email. Please try again.');                                    
                    }


                                exit();
        });

The code works correctly first time. However if I submit the code without page refresh the previous response is received. Like if I load the page for the first time and I get reponse from sample.php as 0 the message is displayed correctly. However if I give an ajax call without page refresh and I get response from sample.php as 1, the previous message is displayed. Whatever output I get I will get the same message for all until I refresh the page. What’s the problem? Code works correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:15:33+00:00Added an answer on May 24, 2026 at 6:15 am

    Your responses are being cached so you need to prevent that. There are three widely used solutions in case you use jQuery.

    Setting up jQuery (instructs AJAX calls not to cache results)

    $(document).ready(function(){
        $.ajaxSetup({ 
            cache: false 
        });
    });
    

    Random Math seed (added to the URL its makes the server believe its a new request)

    $.ajax({
        type:"POST",
        url: 'sample.php?rnd=' + Math.random(),
        data:"data="+data,
        success: function(server_response) { 
        //... rest of the code      
    });
    

    Using current timestamp as seed (same as previous except current timestamp is used)

    $.ajax({
        type:"POST",
        url: 'sample.php?rnd=' + Date().getTime(),
        data:"data="+data,
        success: function(server_response) { 
        //... rest of the code      
    });
    

    The first option is good in case a lot of ajax requests are made on a single page with no actual downsides.

    The second option is almost always a good choice. It also has no particular downsides.

    The third option is also good but it can be dangerous on pages which make more than one AJAX request per second because sometimes the same timestamp could be used for two different requests and the subsequent call will receive cached data.

    EDIT: In case no $(document).ready() is present on the page one can be added to the head section right before the ending </head> tag.

    <head>
        <!-- Whatever code already exists in the head section -->
        <script type="text/javascript">
            $(document).ready(function(){
                $.ajaxSetup({ 
                    cache: false 
                });
            });
        </script>
    </head>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed code with Ajax and jQuery. I have got a response from
We have got loads of options for php + MySQL + Apache combo... Which
I have got a C function in a static library, let's call it A,
I have got some code to load an assembly and get all types, which
I have got the following code from here to read an Excel file using
I have the following code in my view: <% using (Ajax.BeginForm(JsonCreate, new AjaxOptions {
I have this AJAX code, but it doesn't seem to throw the 'alert' method.
We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible
I have got a python script which is creating an ODBC connection. The ODBC
I have got the following problem since the server has safe mode turned on,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.