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

  • Home
  • SEARCH
  • 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 6885661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:39:45+00:00 2026-05-27T05:39:45+00:00

Every second this script will open a page using AJAX and return the contents

  • 0

Every second this script will open a page using AJAX and return the contents into a new div on this page, which it creates on the fly. But unfortunatly, they div’s go under each other. And I would like to create each new div at the top. I don’t really want to use jquery or anything similar.

Any assistance with this is greatly appreciated, I’m not very confident with JS so if it’s not obvious why, could you please give me a small explanation too. 🙂 Thanks

function timedCount()
{
  min = Math.floor(s/60);
  sec = s-(min*60);
  if(sec < 10) { sec = '0'+sec; }
  if(min >= 60) { min = min-15; }
  if(quit == 0) { document.getElementById('mTime').innerHTML = min+':'+sec; }
  s=s+1;
  var ajaxRequest;
  try { ajaxRequest = new XMLHttpRequest(); }  catch (e){
    try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
      try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){
        alert("Your browser broke!");
  return false;
      }
    }
  }
  ajaxRequest.onreadystatechange = function()
  {
    if(ajaxRequest.readyState == 4 && ajaxRequest.responseText != '')
   {
        if(ajaxRequest.responseText == 'HT') {
        document.getElementById('mTime').innerHTML = 'Half Time';
        t=setTimeout("timedCount()",(3600-s)*1000);
        quit=1;
       return;
    }
    if(ajaxRequest.responseText == 'FT') {
      document.getElementById('mTime').innerHTML = 'Full Time';
      quit=1;
      return;
    }
    el = document.createElement('rep'+i);
    el.innerHTML = ajaxRequest.responseText +'<br>';
    document.getElementById('container').appendChild(el);
    i=i+1;
  }
}
ajaxRequest.open("GET", "getMatch.php", true);
ajaxRequest.send(null);
}
  • 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-27T05:39:45+00:00Added an answer on May 27, 2026 at 5:39 am

    You want the insertBefore function

    var parent = document.getElementById('container');
    parent.insertBefore(el, parent.firstChild);
    

    Note that if parent is empty, and parent.firstChild is therefore null, then el will be inserted at the end of parent, which is what you’d want.

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

Sidebar

Related Questions

I am trying to make an script that will every second read string from
I am trying to implement a php script which will run on every call
I'm writing this script to rotate a background Image every 3 seconds but it
I have a loop which basically calls this every few seconds (after the timeout):
Every Hello has a response. Second TTY will send a hello to the sender
I am attempting to build a script that will log data that changes every
Every ajax chat tutorial ends the same. You run a getChatMsg.php or some script
I would like run a PHP script that runs every second to update a
This is my first attempt at AJAX, and I'm running into three specific problems.
I want to create a timer in PHP that will count down every second.

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.