Pergunta

i have a form, say like this :

<form name="form1" action="" method="post">
<input type="text" name="tfcari" />
<input type="submit" name="btcari" />
</form>

<?php
if (isset($_POST['btcari'])) {

echo $_POST['tfcari'];  

?>

how to doing like this :

click submit - echo text - wait for 5 seconds - echo text (automatically) - wait for 5 seconds - echo text (automatically) - ...

thanks all.

Foi útil?

Solução

PHP pre-processes before sending to the website, so if you were to put a sleep method, it would only delay the page frrom displaying for that long.

The -easiest- way will be to use jQuery for an ajax call, then use setTimeout to echo text every 5 seconds:

// Assuming jQuery is linked
$(function() {
    // Connect to the php file
    $.ajax({
        url: 'php-file-with-tfcari-var.php',
        type: 'POST',
        success: function(data) {
            // data is what the ajax call returns, let's assume it's the $_POST variable from php
            var tfcari = data.tfcari;
            // Now you can loop every 5 seconds with a self calling setTimeout method
            var poll = (setTimeout(function() {
                window.document.write(tfcari);
            }, 5000)();
        }
    });
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top