Reputation: 5325
I want to call a jquery code in every 5 sec interval for that i am using following code but this code is not calling in repeatedly
My code is
setInterval($.getJSON('friendshipRequestCount', function(data) {
var cnt=data.totalFriendshipRequestCount;
if(cnt>0){
$('#f-request-count').css("display","block");
$('#f-request-count').html(data.totalFriendshipRequestCount);
}
else{
$('#f-request-count').css("display","none");
}
}),5000);
Please see what is the problem
Upvotes: 0
Views: 75
Reputation: 113345
Pass a function as first parameter in setInterval. $.getJSON
returns a jqXHR
setInterval(function () {
$.getJSON('friendshipRequestCount', function(data) {
var cnt=data.totalFriendshipRequestCount;
if(cnt>0){
$('#f-request-count').css("display","block");
$('#f-request-count').html(data.totalFriendshipRequestCount);
}
else{
$('#f-request-count').css("display","none");
}
});
}, 5000);
Upvotes: 2
Reputation:
setInterval
needs to be passed a function, not the result of getJSON
.
setInterval(function () {
$.getJSON('friendshipRequestCount', function (data) {
var cnt = data.totalFriendshipRequestCount;
if (cnt > 0) {
$('#f-request-count').css("display", "block");
$('#f-request-count').html(data.totalFriendshipRequestCount);
} else {
$('#f-request-count').css("display", "none");
}
});
}, 5000);
Upvotes: 4