Hi everyone,

For a social system I am working on, I am in desperate need of being pointed in the right direction for how to create a live ajax feed which calls data from a database.

Urgently needed, any help much appreciated!

Cheers!

Jack(Scaasiboi)

Look here:

http://api.jquery.com/load/

Depending on how often you want your feed to be updated you could use a Javascript setInterval() function to repeatedly call the .load ajax feed.

Here is something I've used in the past (to update a price of an item every couple of seconds).

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function updateBids() {
	var url="getprice.php?auc=<?php echo $id; ?>";
	jQuery("#priceElement")<strong class="highlight">.load</strong>(url);
}

<strong class="highlight">setInterval</strong>("updateBids()", 1000);
</script>
</head>
<body>
Here is the price: <div id="priceElement"></div>
</body>
</html>

Simple (behind-the-scenes) PHP script to fetch data from db:

<?php

// Anything printed on this page will be loaded into the priceElement <div>

                include ('db.php');

		$id = $_GET['auc'];
		$getprice = mysql_query("SELECT b_currentprice FROM bid WHERE auction_id = '$id' ORDER BY b_timestamp DESC");
		$resultprice = mysql_fetch_assoc($getprice);
		
		$price = $resultprice['b_currentprice'];
		echo $price;
?>

Cheers for that I modified the jquery slightly and altered it to work with my existing php calling script, and it works awesomely!

Cheers!

is it same as?:

setInterval(function() {
    $("#balance_view").load("balance.php");
}, 500);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.