0

hi, i use AJAX, framework - JQUERY.
Now all information show in one table( <div id = "user">).

var user= setInterval(function()
{
$('#user).load(user.php?id='+ Math.random());
}, 5000);

user.php:

$rez= mysql_query($sql, $db) or die("Error");
while($r = mysql_fetch_array($rez, MYSQL_ASSOC )){
$name= $r["name"]; 
$time= $r["time"];

But how make this:

$name show in div name, and $time show in div time.
One file, and two <div>
I hope to understand my trouble

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Lolalola
0

Lola,

Try this:

var user = setInterval(function(){
	$.get( user.php, { id : Math.random() }, function (data) {
		data = data.split('||');
		$("name").html(data[0]);
		$("time").html(data[1]);
	});
}, 5000);
$rez= mysql_query($sql, $db) or die("Error");
$r = mysql_fetch_array($rez, MYSQL_ASSOC );
echo $r["name"] . '||' . $r["time"]
exit;

Note how '||' is used as a separator that allows the combined string returned by user.php to be re-split in javascript back into its component parts (name and time).

I've not tested so it may need debugging.

Airshow

0

Just found time to test.

Use this javascript in place of that posted above:

$(document).ready(function(){
	var user = setInterval(function(){
		$.get( 'user.html', { id : Math.random() }, function (data) {
			data = data.split('||');
			$("#name").html(data[0]);
			$("#time").html(data[1]);
		});
	}, 5000);
});

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.