473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Ajax automatic refresh a DIV

hi all
i want to refresh a div using ajax,

i wrote this code:

index.php
Expand|Select|Wrap|Line Numbers
  1. <script src="ajax/moniter/moniter.js" type="text/javascript"></script>
  2. <body onload="moniter();">
  3. <div id="moniter">
  4.  
  5.       </div>
  6. </body
  7.  
moniter.js
Expand|Select|Wrap|Line Numbers
  1. // JavaScript Document
  2. var xmlHttp_moniter
  3.  
  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)
  16.  
  17. }
  18.  
  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. }
  27.  
  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. }
  49.  
  50.  
  51.  
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 10069
hsriat
1,654 Expert 1GB
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
hsriat,

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
acoder
16,027 Expert Mod 8TB
...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
hsriat
1,654 Expert 1GB
@acoder
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

12
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...
3
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...
10
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....
25
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....
10
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 -------------...
5
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...
1
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..
4
kelleyvanevert
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
0
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...
0
agi2029
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,...
0
isladogs
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...

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.