Click here to Skip to main content
15,915,777 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I currently have a dashboard where I am using various social API to pull follower counts, page likes, etc...

I have a setInterval function setup to refresh and make a new ajax request every 3 minutes so that the counts are always updated on the dashboard.


My question is; I want to have notifications show each time the ajax request returns a new value. New meaning different than the last known value before the latest refresh, and then output text for example;

"You have x new Likes on your Facebook Page"

var x = data.new_count - data.old_count;


DOMSubtreeModified
DOMNodeInserted
DOMNodeRemoved

^^ Are all deprecated, and would have solved this problem in the past, but now I am without a solution.

I am trying to avoid saving the value to the database and instead do the functions on the fly.

Any help is appreciated.
Posted
Comments
Sergey Alexandrovich Kryukov 5-Jan-16 17:46pm    
Can't you use server push instead? WebSocket API, SignalR? Polling is really too bad...
—SA
zakpucci2 5-Jan-16 18:03pm    
I'm not entirely sure how to use server push in this situation. Most of these social API need you to re-authenticate just to gather simple information. I happened to find a way around it where the counts can be updated with a simple ajax call. Issue is, I'm not storing the counts anywhere to compare to, all data is pulled and then discarded and replaced. No where am I storing the initial value.

The ideal situation is to watch the parent <div> for change and fire scripts at that time. Looks like it isn't going to work though.
Sergey Alexandrovich Kryukov 5-Jan-16 18:19pm    
I'm not sure, too, but I don't know what you have on the server side, but you should know. Polling is the apparent nightmare.
—SA
zakpucci2 5-Jan-16 18:23pm    
I can see why it would be a nightmare. Currently with my setInterval functions at times if the server hangs, the intervals catch up and it's just an absolute cluster.

Polling even though it seems like a nightmare, does seem very solid in solving that issue as well.

Might be worth the nightmare. :)
Sergey Alexandrovich Kryukov 5-Jan-16 18:27pm    
Because this is wasteful.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900