playaz Posted May 10, 2010 Share Posted May 10, 2010 Hi guys, I've not done too much AJAX in the past so feel free to correct me if I am wrong on any occasion.. I want to poll an events database table every 60 seconds, and run an mysql query to grab all upcoming events, an upcoming event should pop up to screen ideally in a modal window. Can anyone suggest how I could do this or point me in the right direction - thanks in advance. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted May 10, 2010 Share Posted May 10, 2010 You could have a JavaScript function that runs every 60 seconds, either using setTimeout or setInterval, that will call an AJAX/PHP script that searches the DB. Quote Link to comment Share on other sites More sharing options...
playaz Posted May 12, 2010 Author Share Posted May 12, 2010 I've done the following - it all works too! I just want to perform a simple alert() if the ajax returns succesfully - here is my code Note - post.php just does a select statement limited to 1 row (this works fine and returns an array to the #responsecontainer) Can anyone explain how i'd change the code to do this:- 1) if ajax returns succesfully pop up an alert box 2) the returned content in the responsecontainer is always string but the post.php returns an array (i'm guessing some json maybe required?) How can I get this returned content as an array and not a string (as i'll need for another function for creating a jquery dialog box. <script> $(document).ready(function() { var refreshId = setInterval(function(){ $.ajax({ type: "POST", url: "post.php", data: "", success: function(html){ $("#responsecontainer").html(html); } }); }, 1000 ); }); </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.