473,503 Members | 5,495 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:

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 10073
hsriat
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
eihabisaac
38 New Member
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 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
hsriat
1,654 Recognized Expert Top Contributor
@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
1435
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
2891
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
3135
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
2518
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
3426
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
3170
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
967
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
5272
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
7207
marktang
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,...
0
7093
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
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
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
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
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...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
402
bsmnconsultancy
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...

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.