-2

I found this script in W3 school.

<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#div1").load("demo_test.txt");
    });
});
</script>

What this script does is when ever a person click the button it will load the demo_text.txt. What I need is to make it load every 30 sec.

Help me please.

Khaled Awad
  • 1,644
  • 11
  • 24
typicalnoob
  • 11
  • 1
  • 4

2 Answers2

3

Try using window.setInterval:

<script>
$(document).ready(function(){
    window.setInterval(function () {
        $("#div1").load("demo_test.txt");
    }, 30000);
});
</script>
TAGraves
  • 1,369
  • 1
  • 9
  • 11
  • thank you it work! – typicalnoob Apr 13 '16 at 00:24
  • Glad to help! If this or any answer has solved your question, please consider accepting it by clicking the check-mark. Doing so indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is, however, no obligation to do this. Happy coding! – TAGraves Apr 13 '16 at 00:26
0

A ajax solution I would prefer:

$(document).ready(function(){
    $("button").click(function(){
        var loop = setInterval(function(){
            $.ajax('demo_test.txt', {

            }).done(function (txt) {
                $("#div1").html(txt);
            });
         }, 30000);           
    });
});
  • This is incorrect. `setInterval()` takes the *timer* argument, not `$.ajax()`. Plus you failed to include the closing parenthesis for `setInterval(` – mferly Apr 13 '16 at 00:20
  • Sorry, lost the overview couse im doing it with my smartphone. –  Apr 13 '16 at 09:42