473,657 Members | 2,478 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 5276
acoder
16,027 Recognized Expert Moderator MVP
For the timer, use window.setInter val(). 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
2459
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 individual pages are called, I would always want them refreshed from the server. This is no matter what setting is used by the local browser. The closest KB article I found was Q200131, but that was not helpful to me.
52
5430
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. Happy New Year -- Gerry
6
2531
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 the data is refreshed, however if you try to refresh the report the onreadystatechage does not seem to fire. I have tested this by placing an alert in the verifyID2 & verifyID3 function to track where the XMLHttpRequest currently is. Now when...
0
1833
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 button etc) and a dataset to provide the data to populate these fields. I'm tring to do this using composite controls. I would have a control to display a single record (formview), another control to display a grid of records (datasheet), another...
10
3149
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 to much impact on my web server. The refresh action should be taken only when something
10
3456
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 works fine when viewing it statically or with a META REFRESH header tag. The idea is to give the user...
1
2045
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 working. Any ideas? <%@ Page Language="VB" AutoEventWireup="false" CodeFile="default-ajax.aspx.vb" Inherits="pages_verify_groups_Default" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
29
8153
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"> //Global vars to hold connection to web pages var request;
4
10079
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
8420
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8516
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.