Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update website via AJAX in realtime

Status
Not open for further replies.

RandyRiegel

Programmer
Sep 29, 2003
256
US
I have a client that wants to be able to update a website in real time. Here is the scenario:

1.) There is a menu (restaurant) that has a menu displayed on monitors.
2.) They want to be able to update the menu real during business hours without the whole page refreshing.
3.) They want either a .NET app or an webpage to be able to update the menu from their computer in the back room.

So, pretty much I need to send a "remote ajax" call to modify the page. I know that once a page is loaded it's pretty much disconnected from the server. That is the problem. Any ideas?
 
using jQuery (for ease) something like this is fine
Code:
<!DOCTYPE HTML >
<html>
<head>
	<title>Menu</title>
	<script src="[URL unfurl="true"]http://code.jquery.com/jquery-1.10.1.min.js"></script>[/URL]
	<script type="text/javascript">
		function refreshMenu(){
			$.ajax({
				type: 'GET',
				cache: false,
				ifModified: true,
				dataType: 'html',
				success: function (data){
					var newData = $(data).filter('#menu').html();
					if (typeof newData != 'undefined' && newData != $('#menu').html() ) {
						$('#menu').html(newData);
					}
				}
			});
		}
		var refreshInterval = 10; //in seconds
		var refreshTimer = setInterval(refreshMenu, (refreshInterval * 1000));
	</script>
</head>
<body>
	<!--- CHANGE ONLY THE INSIDE OF THIS DIV --->
	<div id="menu">
		<ul>
			<li>
				Menu item 1
			</li>
			<li>
				Menu item 2
			</li>
			<li>
				Menu item 3
			</li>
			<li>
				Menu item 4
			</li>
		</ul>
	</div>
	<!--- CHANGE ONLY THE INSIDE OF THE ABOVE DIV --->
</body>
</html>
 
A JAVA applet would be safer than a javascript loop with the associated resource hogging.


that has a menu displayed on monitors.

But if they are just monitors what is the browser going to run on???


Or are these monitors connected directly to the backoffice PC?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
The monitors are going to be displayed from a thin client (I need to get specs on this still). The thin client is going to have a web browser of some type on it and be networked through computer in back room.

What I'm really trying to do is basically sending an AJAX POST to change the DOM of the remote webpage without refreshing the whole remote page. Right now my plans are to use PHP for the website. I definitely don't want the page hitting a database every minute as this would be a lot of overhead (there are going to be other locations getting their menu too once this TRIAL is up and running). I've got some search results for JSONP because it can make requests from another domain, etc. Haven't researched a lot into it yet though.

 
look at the code I posted.

if you don't want to retrieve the _whole_ page each time, instead of pointing the $.ajax command at the same page, point it at an api server.

eg
Code:
$.ajax({ url: 'api.php', etc});

then in the api.php do something like this

Code:
<?php 
session_start();

function hasChangedSince($time){
  //compare times
}
function getNewMenuItems(){
  //grab menu items return as an ordered array of items and prices
}
if( hasChangedSince($_SESSION['lastCheckedIn'])):
  echo json_encode(array('changed'=>false);
  die;
else:
  $array = getNewMenuItems();
  echo json_encode(array('changed'=>true, 'menu'=>$array));
  die;
endif;

?>
 
Here are the specs my friend (and client) gave me:

The web modifications are done via the Stores Back-Office computer not from Thin Client
That is why the other company has a 15 minute polling / refresh timer.
Their program checked for updates once every 15 minutes - too slow.
Is there any way to "PUSH" the refresh out to that store's Thin Client?
Or can the Back-Office Computer send a "TCP/IP" message to the Thin Client to "PULL", now.
The Thin Client is actually mounted on the back of the 50" display.
NO Keyboard and NO Mouse connected to Thin Client during "Normal Operations".
Keyboard and are Mouse connected only for initial install or break-downs.
Normally, the Thin Client just has Video cable, Network cable and Power cable connected.

No human intervention with THIN CLIENT ...
1) In the morning, we turn the power on
2) It boots O/S
3) It loads "some kind of web screen displaying" program
4) It automatically logs in & connects to the Web Server.
5) It downloads that Stores Digital Menu.
7) Automatically go to F-11 Full Screen / Border-less mode.
6) Display the Menu all day long and with some changing or moving graphics sections, too.
7) At night, we turn the power off.

Randy
 
With Java ... yes.

With javascript ... No.





Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top