473,508 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX automatic page refresh (with php pages)

kelleyvanevert
3 New Member
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 would probably be better, but I'm learning to master php and MySQL.
The game is shown via the <canvas> tag (using php and mysql to write the javascript, with in its turn writes the <canvas>).

Now it can happen that the game develops in one browser, but the old game board is still shown in the other.
I want to solve this issue using AJAX page refreshing.
I think it's possible to refresh the game every like 10/20/30 seconds, without the page reloading, so the page also doesn't go back to the top every refresh, but stays at it's scroll position.

The clearest answer to my problem i found here:
http://aleembawany.com/2005/09/01/ajax-instant-tutorial/
...now all I really have to do is add an automatic timer, so the div containing the game board automatically refreshes.

...Could someone help me, pretty much step by step? ( I may know a bit about html/php/mysql/css/design and stuff, but I REALLY REALLY suck with javascript. My javascript is usually just copy/paste work... )

Cheers!
Kelley van Evert
Oct 5 '08 #1
4 5272
acoder
16,027 Recognized Expert Moderator MVP
For the timer, use window.setInterval(). If you get stuck, post your code.
Oct 6 '08 #2
kelleyvanevert
3 New Member
Well, you see:

I'm using a javascript function in the <head>, to write to the <canvas> tag.
The tutorial I link to, see above, uses getElementById, but <script> doens't support an id (I think?).
...so how do I reload the data into the head?
Oct 6 '08 #3
kelleyvanevert
3 New Member
This is a part of the <head>, and <body>:

Expand|Select|Wrap|Line Numbers
  1.         <?php
  2.             // displayPageType_game -> 475
  3.             // this is where the javascript is loaded that writes to the <canvas> tag...
  4.             $canvasId = "gameBoard";
  5.             $canvasSize = 475;
  6.             $dotSize = 3;
  7.             $lineSize = 1;
  8.             $lineColor = "#bbbbbb";
  9.             $radiusPixAdjust = -1;
  10.             $extraBorder = 1;
  11.             displayBoard($gameid, $canvasSize, $canvasId, $dotSize, $lineSize, $lineColor, $radiusPixAdjust, $extraBorder);
  12.         ?>
  13. </head>
  14. <body onLoad="canvasDraw();">
  15.  
... and here is the canvas:
Expand|Select|Wrap|Line Numbers
  1.             <canvas id="<?php echo $canvasId;?>" width="<?php echo $canvasSize;?>" height="<?php echo $canvasSize;?>">
  2.             You are using a browser that doesn't support the &lt;canvas&gt; tag.
  3.             </canvas>
  4.  
Oct 6 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
A script tag can have an ID. There's no JavaScript in the code that you posted above. Post that too.

Note: If you set the src of a script tag, it will execute the code within the source file.
Oct 6 '08 #5

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

Similar topics

1
2445
by: Matthew Ferri | last post by:
I'm using Windows 2000 Pro SP4 and Office 2000 Pro Sp3. I have some dynamic database pages that I do not want a user to see from their local cache of pervious visits to this page. When these...
52
5390
by: Gerard M Foley | last post by:
Can one write a webpage which is not displayed but which simply redirects the user to another page without any action by the user? Sorry if this is simple, but I am sometimes simple myself. ...
6
2512
by: Nico VanHaaster | last post by:
Hello all, I have run across an issue with IE 6.0+. I have a page that makes an XMLHttpRequest to the webserver to update a report on the page. The first time you hit the refresh report button...
0
1828
by: angiemc | last post by:
Hi, I have a question about AJAX and ASP.Net controls. I'm working on a system that requires pages to be generated dynamically based on XML to provide the layout (eg text boxes, dropdowns, save...
10
3136
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
3427
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 -------------...
1
2034
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped...
29
8124
by: canabatz | last post by:
Hello , i got this code that works great , now i want to have it refresh every 4 seconds , where can i put the timer to do that? i realy need help!! thanx!! <script type="text/javascript">...
4
10074
by: eihabisaac | last post by:
hi all i want to refresh a div using ajax, i wrote this code: index.php <script src="ajax/moniter/moniter.js" type="text/javascript"></script> <body onload="moniter();"> <div id="moniter">
0
7224
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
7380
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...
1
7039
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
7494
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
5626
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,...
1
5050
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...
0
3192
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
1553
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
415
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.