user114752
user114752

Reputation:

jQuery - If a database is updated, update the page

Righteo, Just started messing with Jquery, and I can update a database etc with it, but I want to know if there is a way to display new info posted into a database (even if it is not what was just posted) without a reload etc.

Don't write it out for me, just point me in the right direction... I want to pull it together myself.. best way to learn :D

Upvotes: 2

Views: 2160

Answers (3)

Aslan Kaya
Aslan Kaya

Reputation: 524

 var dataString="variable="+variablevalue;
    // Check if there is any updates every 3 second.
    var x=setInterval(doUpdates,3000);

    function doUpdates() {
        $.ajax({
        type: 'POST',
        url: "yourfile.php",
        data: dataString,                 
        success: function(data) {
            $('#yourid').html(data)
            //This will update the HTML code.
        }
    })

Upvotes: 1

Kris
Kris

Reputation: 14468

The only way is to have the web page regularly poll the server for new info.

There is no way to initiate interaction from the server side.

Edit:

No way except to use a framework that handles the polling for your.

Upvotes: -1

Nosredna
Nosredna

Reputation: 86336

Easiest solution is to poll to server periodically.

If you want the server to push to you, use Comet.

Upvotes: 1

Related Questions