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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:58:34+00:00 2026-05-23T19:58:34+00:00

This my script: <script type=text/javascript> var auto_refresh = setInterval( function () { $(‘#alert_div’).load(‘/check_messages.php?timestamp=<?php echo

  • 0

This my script:

<script type="text/javascript">
var auto_refresh = setInterval(
function () {
$('#alert_div').load('/check_messages.php?timestamp=<?php echo TIMESTAMP2;?>').fadeIn("slow");}, 180000);
$("html,body").scrollTop("alert_div",0);
</script>

Actually, everyting works fine but…
As you can see, every 3 minutes script loads check_messages.php file. If user has new messages messages check_messages.php outputs information, otherwise the output is empty:

echo "";

I need that $("html,body").scrollTop("alert_div",0); exetutes only in case if php script output is not empty.

  • 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-23T19:58:36+00:00Added an answer on May 23, 2026 at 7:58 pm

    The load function takes a function as a parameter, which is called when the request completes with the response text as the first parameter. You can check whether the response was empty in this callback function and scrolling to the top if not then.

    Requests such as load are handled asynchronously, which means that the code that is immediately after it will be run before the call has completed. If you want something to happen after the call has completed then you need to include it in the completion callback. For this reason I do not expect your fadeIn call to work, as I don’t think the load function returns the included element. When the load call returns, your text has not been included in the document.

    I’ve also taken the liberty of moving the code out of your anonymous function into one called check_messages. In your code you had the scroll to top outside the setInterval call so it was being executed immediately, rather when the messages were checked.

    <script type="text/javascript">
    function check_messages() {
        $('#alert_div').load('/check_messages.php?timestamp=<?php echo TIMESTAMP2;?>',
             function(responseText, textStatus, XMLHttpRequest) {
                  if(responseText != "") {
                      $("html,body").scrollTop("alert_div",0);
                  }
             }).fadeIn("slow");
    }
    
    var auto_refresh = setInterval(check_messages, 180000);
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: <script type=text/javascript> function js() { var getJs = document.getElementById(jogo); if
Look this code: <script type = text/javascript> function mouseClick (container) { container.appendChild (document.createTextNode (Can
The code is like this: var script = document.createElement('script'); //script.type = 'text/javascript'; // do
Below is the code for my YWA wrapper var astr_ywascript = (document.createElement(script).type = text/javascript).src
I was wondering if anyone here had some experience writing this type of script
I am currently using this script to get new data every second from record_count.php
javascript:var width=1900; var height=800; var jQueryScriptOutputted = false; function initJQuery() { if (typeof(jQuery) ==
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
I'm using this script to display all the images in a folder, but I
Well basically I have this script that takes a long time to execute and

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.