Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  66] [ 4]  / answers: 1 / hits: 25113  / 10 Years ago, wed, april 9, 2014, 12:00:00

I want to implement a ajax call to a page every 3 seconds.
It will either return 0 if false or a html snippet like <div>Content</div>



How should I proceed to place or remove that div on the page according to what ajax returns ?


More From » jquery

 Answers
125

Use setInterval()



setInterval(ajaxCall, 3000);

function ajaxCall() {
$.ajax({url:url,
type:'html',
success:function(result){
if(result==0)
$('#content').hide();
else
$('#content').html(result).show();

}
});
}



<div id=content>Content</div>

[#71555] Monday, April 7, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elians

Total Points: 417
Total Questions: 87
Total Answers: 101

Location: Barbados
Member since Sun, Nov 27, 2022
2 Years ago
;