Question

Currently im using PrivatePub(faye) in a rails app for chat but so far every post i read it looks like faye is unable to provide a count of open sockets subscribed to a specific event(or chat room) So unless anyone here can give me a better idea of how to approach this issue then ill be hacking up a fix for this issue but an explanation of how im going to do that is beyond what i need to ask in this post.

(Counter URL) http://bloggingsquared.com/jquery/flipcounter/ I've found a counter I would like to use but i know very little JavaScript and looking through the options of this script it doesn't seem to have an option to pull data from a JSON url. I would like to know if it is easy to make this counter do a $.getJSON() and set it to a timer to pull every 20 seconds?

Please if you have any other solution to my issue speak up or you can simply help me out on how to make the counter read JSON from a url on an interval.

Thanks in advance.

Was it helpful?

Solution

You can set up a timer using setTimeout() or setInterval():

Jquery/Ajax call with timer

And inside the success response of an AJAX request set the counter:

$.ajax({
  url: "test.php",
  success: function(r){
     $("#counter").flipCounter("renderCounter", r.count);
  }
});

This is assuming that "r" is a JSON response, that has "count" inside it. If you're unsure of the response object, just console.log it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top