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 6759143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:53:50+00:00 2026-05-26T13:53:50+00:00

I have an AJAX function to check for new messages and then prepend the

  • 0

I have an AJAX function to check for new messages and then prepend the new messages to the #message. But, my problem is that this function triggers every 20 seconds, but whenever you click the Refresh button that instantly triggers the function, it messes up. Here is my functions for the AJAX:

function ajaxMail() {
    var message_id = $('.line:first').attr('id');
    jQuery.ajax({ //new mail
        type: 'get',
        dataType: 'text',
        url: "/employee/message/check_mail.php",
        data: {
            latest_id: message_id,
            t: Math.random()
        },
        success: function(data, textStatus) {
            $('#messages_inner').prepend(data);
        }
    });
}

function updateTitles() {
    //if(titleChange !== false) {
    $.get('update.php?type=title', function(data) {
        document.title = data;
    });
    //}
    $.get('update.php?type=header', function(data) {
        $('#heading').html(data);
    });
    $.get('update.php?type=total', function(data) {
        $('#total').html('Total messages: ' + data);
    });
    setTimeout("updateTitles();ajaxMail();", 20000);
}
updateTitles();

And for the Refresh button this is what I use:

$(document).ready(function() {
    $('#refresh').click(function() {
        ajaxMail();
        updateTitles();
    });
});

Sometimes, the same exact message gets prepended to the message div because of the button or something. (but when I refresh of course there aren’t 2 of the same message anymore) This is one time when the same message was prepended multiple times:

enter image description here

First, I pressed the Refresh button and it prepended the new message. But then about 5 seconds later the funciton triggered again and for some reason prepended the same message again. Also as you can see the Inbox count says 2 because really there is only 2 (“Test” and “Test12345”), but for some reason the “Test12345” got prepended 2 times.

Does anyone know why it is doing this? I can also provide the code for check_mail.php if you need to see it.

  • 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-26T13:53:50+00:00Added an answer on May 26, 2026 at 1:53 pm

    I’d recommend trying cache:false too, I’ve had browsers caching an ajax request even through I was sending a random string along.
    Also, consider clearing the timeout before you set it again, as each time the refresh button is pressed it starts another timeout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery AJAX function where I check for new messages and if
I have an ajax call that fires multiple times but is called once. function
I have a jquery-ajax function that sends data to a php script and the
The problem seems very strange. I have a AJAX helper function within a same
The problem is the following. We have lots of ajax call via $.ajax function.
I am using the jQuery $.ajax() function. I have put this into a parent
I have a function: $(.delete).click(function() { $.ajax({ url: ServerHandler.ashx, data: mode=delete&item= + $(this).attr(title), success:
I have an Ajax script that allows me to check a form without refreshing
New to Rails and even newer to Ajax. I have a page that displays
I'm kind of new to jquery/ajax calls, I have this code below to pull

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.