473,569 Members | 2,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ajax automatic refresh a DIV

38 New Member
hi all
i want to refresh a div using ajax,

i wrote this code:

Expand|Select|Wrap|Line Numbers
  1. <script src="ajax/moniter/moniter.js" type="text/javascript"></script>
  2. <body onload="moniter();">
  3. <div id="moniter">
  5.       </div>
  6. </body
Expand|Select|Wrap|Line Numbers
  1. // JavaScript Document
  2. var xmlHttp_moniter
  4. function moniter()
  5. {
  6.     xmlHttp_moniter = GetXmlHttpObject_parcel()
  7.     if(xmlHttp_moniter == null)
  8.     {
  9.         alert("browser does not support HTTP Request")
  10.         return
  11.     }
  12.     var url="ajax/moniter/moniter.php"
  13.     xmlHttp_moniter.onreadystatechange = stateChanged
  14.     xmlHttp_moniter.open("GET",url,true)
  15.     xmlHttp_moniter.send(null)
  17. }
  19. function stateChanged()
  20. {
  21.     if(xmlHttp_moniter.readyState==4 || xmlHttp_moniter.readyState == "complete")
  22.     {
  23.         document.getElementById("moniter").innerHTML = xmlHttp_moniter.responseText
  24.         setTimeout('moniter()',100);
  25.     }
  26. }
  28. function GetXmlHttpObject_parcel()
  29. {
  30.     var xmlHttp_moniter=null;
  31.     try
  32.     {
  33.         xmlHttp_moniter=new XMLHttpRequest();
  34.     }
  35.     catch (e)
  36.          {
  37.              //Internet Explorer
  38.              try
  39.               {
  40.                   xmlHttp_moniter=new ActiveXObject("Msxml2.XMLHTTP");
  41.               }
  42.              catch (e)
  43.               {
  44.               xmlHttp_moniter=new ActiveXObject("Microsoft.XMLHTTP");
  45.               }
  46.          }
  47.     return xmlHttp_moniter;
  48. }
it work but the results are always the same from moniter.php file

where is the problem or if anybody know a better way to do ajax div refresh

thanks in advance
Apr 10 '09 #1
4 10078
1,654 Recognized Expert Top Contributor
Try this:
Expand|Select|Wrap|Line Numbers
  1. var url="ajax/moniter/moniter.php?random=" + Maths.random()
This will make sure new request is made every time, instead of picking the content from the local cache.
Apr 10 '09 #2
38 New Member

You are the man;

thank you,

if anybody wants to use this code, just add hsriat line and it will work perfectilly
Apr 10 '09 #3
16,027 Recognized Expert Moderator MVP
...except that it's Math. To be completely sure that it's unique, use a timestamp: (new Date()).getTime ()

You could also set headers to make sure the page is not cached.
Apr 10 '09 #4
1,654 Recognized Expert Top Contributor
My mistake... but I wonder how did it work if he used Maths.
Apr 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Griff | last post by:
The use of AJAX as an approach seems to be taking off. Is this correct, or have I just read the hype? Is Ajax a proven approach that one should look at for building high-load websites? If yes, can anyone recommend good reading material? I see that there is a Wrox Professional Ajax book, but I've not seen any
by: Beshoo | last post by:
hey gaiz plz I want to cerate log in system in ajax i do it but i have one problem AFTER I start thes session then press refresh key the session gone !!! in other words , after the user type hid username and password I send this information by XMLrequest to php file which verify the user name and the password if trure open the sesstion and...
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e. every 5 seconds, i just want to refresh it ONLY on server change just like desktop applications do. The problem is that refreshing evry n seconds has...
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e. every 5 seconds, i just want to refresh it ONLY on server change just like desktop applications do. The problem is that refreshing evry n seconds has...
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario ------------- I have perl script which simply runs a ps on a Solaris server and generates a static html page with all of the code perfectly and this html page...
by: Kaante | last post by:
Hi, I basically have two frames on my page, the top one contains users stats and the bottom frame contains the website. I want to have a message icon on the top frame which would flash once the user gets a new message. Obviously I would have one message icon which doesn't flash and another which does. Right now i refresh the top frame...
by: luigi.corrias | last post by:
Hello everybody, this is a very difficult question… imagine 2 webform asp.net A and B B is an iframe inside A..
by: kelleyvanevert | last post by:
Hello everyone, This question is often asked, and I know there are lots and lots of answers that I could be using, but I just want a clear good answer. I am making a website (for playing a game called Go). It has a page for each game of course. I'm making the website in PHP and MySQL, I know that for 'real-time' games another solution...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.