I want repeat this code every 4 seconds, how i can do it with javascript or jquery easly ? Thanks. 🙂
$.get("request2.php", function(vystup){
if (vystup !== ""){
$("#prompt").html(vystup);
$("#prompt").animate({"top": "+=25px"}, 500).delay(2000).animate({"top": "-=25px"}, 500).delay(500).html("");
}
});
Another possibility is to use
setTimeout, but place it along with your code in a function that gets called recursively in the callback to the$.get()request.This will ensure that the requests are a minimum of 4 seconds apart since the next request will not begin until the previous response was received.