Current location: Hot Scripts Forums » General Web Coding » JavaScript » refreshing


refreshing

Reply
  #1 (permalink)  
Old 12-17-08, 09:04 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
refresh just one value

Hi there,

I got a value on my site (a price) which will increase if someone
place a bet (by submitting a form). I want this price to "be updated"
each 2 sec. But not my entire site, because then the data that is filled in the
form will dissapear each 2 seconds.

Who knows how to fix this?..

_j
Reply With Quote
  #2 (permalink)  
Old 12-17-08, 02:34 PM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
A touch of javascript may be required. Or place the price display in an iframe and refresh the frame every 2 secs
__________________
Always sanitise your data


Best regards
Reply With Quote
  #3 (permalink)  
Old 12-18-08, 03:43 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
refreshing

Hi there,

I get this value from my database:

PHP Code:

$check mysql_query("SELECT * FROM example WHERE checking='yes'") or die(mysql_error()); 

$nrcheck mysql_num_rows($check);

$begin "15000";
$huidig = ($nrcheck*250)+$begin
This is displayed on my site. Now I want this value to be updated every second.
So it needs to be determined each second and be refreshed on my site..

How to solve this??..

_j
Reply With Quote
  #4 (permalink)  
Old 12-18-08, 03:53 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I merged your threads. Please do not cross-post...


And you need AJAX to achieve this. This tutorial is pretty straight-forward.

http://www.tizag.com/ajaxTutorial/
Reply With Quote
  #5 (permalink)  
Old 12-18-08, 04:09 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
thnx nico...

I'll give it a try there... even though I'm not that good in javascript and AJAX..
Reply With Quote
  #6 (permalink)  
Old 12-18-08, 07:53 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
I got it working in my mac browser (safari and FF) but in
IE I got an error that the access is denied on this line:

xmlHttp.open("GET","http://www.mysite.nl/teller.php",true);

I got really no clue where it comes from.. can some help me out here?..

_j


this is the total script:

Code:
<script type="text/javascript">
function Ajax(){
var xmlHttp;
	try{	
		xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
	}
	catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
		}
		catch (e){
		    try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("No AJAX!?");
				return false;
			}
		}
	}

xmlHttp.onreadystatechange=function(){
	if(xmlHttp.readyState==4){
		document.getElementById('ReloadThis').innerHTML=xmlHttp.responseText;
		setTimeout('Ajax()',1);
	}
}
xmlHttp.open("GET","http://www.mysite.nl/teller.php",true);
xmlHttp.send(null);
}

window.onload=function(){
	setTimeout('Ajax()',1);
}
</script>

Last edited by jonnekke; 12-18-08 at 08:03 AM.
Reply With Quote
  #7 (permalink)  
Old 12-18-08, 08:58 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Try is this way:
Code:
xmlHttp.open("GET", "/teller.php", true);
EDIT:
And change the seconds in setTimeout(). One second isn't enough. People with slow internet connections will have problems. And besides, the number of seconds needs to be in milliseconds. So 1000 = 1 second.
Code:
setTimeout('Ajax()', 1000);

Last edited by Nico; 12-18-08 at 09:00 AM.
Reply With Quote
  #8 (permalink)  
Old 12-18-08, 09:20 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
thnx nico..

the error is gone.. but there is no refresh in IE..
there is in firefox en safari..

what needs to be showed is showed but there
is no refresh..
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating .php file without refreshing page Jarret PHP 3 11-15-06 10:08 PM
Refreshing a frame, when another frame is loaded Dion JavaScript 1 11-19-04 02:18 AM
Single click refreshing with target of _top Deezul ASP 0 09-22-04 06:57 PM
My page does not hold together after Refreshing deastro HTML/XHTML/XML 2 07-27-04 05:05 PM
refreshing external js file fs22 JavaScript 2 06-17-04 11:23 PM


All times are GMT -5. The time now is 11:45 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.