From 5b5dc610bc0da17fd006982de50b4dc74b134a54 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Tue, 5 Jan 2021 20:25:10 -0600 Subject: Refactor likes to use JS to avoid redirect --- src/js/like.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/js/like.js (limited to 'src/js/like.js') diff --git a/src/js/like.js b/src/js/like.js new file mode 100644 index 0000000..cd1e015 --- /dev/null +++ b/src/js/like.js @@ -0,0 +1,11 @@ +function likePost(type, id){ + fetch(`/post/like/${type}/${id}`) + .then(response => response.json()) + .then(response => { + console.log(response) + let btn_id=`btn_${type}_${id}` + let el = document.getElementById(btn_id) + el.innerText = `👍 (${response.likes})` + }) +} + -- cgit v1.2.3