0

I am trying to get Ajaz to pull data from mysql using a php file every 5 seconds and the process continues. It seems to work great in firefox but does not update in IE.

Can anyone help make this platform independent?

Ajax/Jquery Code

function startprogress() {
    $.get("status.php");
    setTimeout('updateStatus()', 500);
}

function updateStatus() {
    $("#progress").load("status.php");
    setTimeout('updateStatus()', 500);
}

PHP File

 mysql_connect("localhost","root","password") or
die("Could not connect: " . mysql_error());

 mysql_select_db("table");

 $sql="SELECT current, total FROM status WHERE id = 1";

 $result = mysql_query($sql);

 while($row = mysql_fetch_array($result))
    {
     echo "Completed: " . $row['current'] ." of " . $row['total'];
    }

Then I have an empty div with id of progress in my HTML file where I have the onClick event to trigger the startprogress() function.

Can anyone help with this?

Thanks much.

2
  • If you want live stuff, you should check something like websocket/node. Also, i think you should use setInterval() instead. Commented Nov 3, 2011 at 21:29
  • Switched to setInterval. Worked great but does not stop when the script is done until I refresh the browser. It works for my purpose though. Commented Nov 11, 2011 at 2:38

1 Answer 1

1

When you use setInterval you should do something like this:

var id = setInterval(function() {
   // Do something each interval
}, 1000);


clearInterval(id); // When you want to clear it

Some exemple here and here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.