Reputation: 954
I am trying to feed 2 divs, .totalmembers
and .totalcomm
from a json file every 60 seconds.
json file looks like this, { "members": { "data": [ { "TotalMembers": 14 } ] }, "communities": { "data": [ { "TotalCommunities": 10 } ] } }
What am I doing wrong here?
$(function FeedTicker() {
$.ajax({
type: "GET",
url: "default.cs.asp?Process=ViewStats",
dataType: 'json',
success: function(data) {
if (index == "members") {
$(".totalmembers").html(data.totalmembers);
} else if (index == "communities") {
$(".totalcomm").html(data.totalcommunities);
}
$('.totalmembers').ajaxSuccess(function(){
$(this).ticker({
pauseOnItems: 6000,
displayType: 'fade',
controls: false,
titleText: ''
});
})
$('.totalcomm').ajaxSuccess(function(){
$(this).ticker({
pauseOnItems: 6000,
displayType: 'fade',
controls: false,
titleText: ''
});
})
}
})
});
Upvotes: 0
Views: 77
Reputation: 12974
One option is to modify your JSON. Something like { totalmembers: 109, totalcommunities : 3}
. That is what it would have to look like if you wanted it to work without modifying your JS.
Another option is to modify your JS. Change your success callback to:
function(data) {
if (index == "members") {
$(".totalmembers").html(data.members.data[0].TotalMembers);
} else if (index == "communities") {
$(".totalcomm").html(data.communities.data[0].TotalCommunities);
}
}
I think it might also be a good idea to move your ajaxSuccess registrations to somewhere outside of your success callback. Currently your code is re-registering the divs every time an ajax request is successful.
Upvotes: 1
Reputation: 17
data.totalmembers
And data.totalcommunities
are may be the List<something>
?
If yes then you have to generate the HTML formation to feed the div
i.e. : data.totalmembers
foreach member in toatalmebers
<table><tr><td>
totalmembers.name </td></tr></table>....
Upvotes: 0