Reputation: 35
The title says it all. When you click like on Facebook, it shows liked and increments the like counter without refreshing the whole page. How it works?
Upvotes: 0
Views: 126
Reputation: 28
Mostly it uses javascript or some framework of javascript. See example. Example gets the current count and if you click the like button it increments by one.
$(".like").click(function () {
var counter = $(".likecounter").text();
counter = parseInt(counter);
counter = counter+1;
$(".likecounter").html(counter);
});
Upvotes: 0
Reputation: 4435
Facebook uses a Javascript framework/library/whatever you want to call it called React, in fact Facebook are the creators / maintainers of React.
What happens is when you click the like button, a javascript variable in the facebook application state gets updated by adding 1 to it. The element is then updated with this new value. It's fairly straight forward stuff, in fact There's even a demo for something similar on the React Redux github page.
Upvotes: 1