Poll database using jQuery/Ajax

Posted by Gav on Stack Overflow See other posts from Stack Overflow or by Gav
Published on 2010-05-12T11:12:36Z Indexed on 2010/05/12 11:34 UTC
Read the original article Hit count: 241

Filed under:
|
|
|

Hi guys,

I am trying to use jQuery (latest version) & ajax to poll a mysql db every x seconds, post.php does a simple search query on the table and limits to 1 row. (eg SELECT id FROM TABLE LIMIT 1)

I've got some other jQuery UI (using v1.8) code that displays some modal/dialog boxes on the screen, simply put if post.php returns something from the db I need to initialise the dialog to pop up onto the screen. I've done all the popup stuff I am just having issues joining all these bits together - i've added some pseudo code of how i expect this to work. Thanks in advance

var refreshId = setInterval(function(){
    $.ajax({
       type: "POST",
       url: "post.php",
       data:  "",
       success: function(html){
         $("#responsecontainer").html(html);
       }
   });  
}, 2000 );s

/* proposed pseudocode */
if (ajax is successful & returns a db row to #responsecontainer) {
   show jQueryUI modal (done this bit already fortunately)
}

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about jQuery