Timer refresh page in a function

In my function I have a page refresh at the end to actually update the table, however the refresh is faster than the database.

Anyone have an idea how I can change this?

echo '<script>                                                                          ';
echo 'function updateId(id) {                                                             ';
echo 'var xmlhttp = new XMLHttpRequest();                                               ';
echo '    xmlhttp.onreadystatechange = function() {                                     ';
echo '        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)                     ';
echo '        {                                                                         ';
//echo '            alert(xmlhttp.responseText);                                          ';
echo '        }                                                                         ';
echo '    };                                                                            ';
echo '    xmlhttp.open("GET", "update.php?id=" +id, true);                              ';
echo '    xmlhttp.send();                                                               ';
echo 'location.reload(true);                                                                ';

echo '}                                                                                 ';
echo '</script>                                                                         ';
?>

Go to Source
Author: Tjerk Peters