Post by Former Member on Aug 5, 2019 10:04:40 GMT -8
So, when we press the likes button, it doesn't automatically add the like to the total. Rather you have to refresh the page and then you see it added. Is there a way that right when you press the likes button one gets added to the total right away and when you press it again (to unlike), one gets taken away right away?
This is an AJAX request and is meant to happen without a refresh. Based on your previous threads, I believe you have code somewhere that's preventing this request (and others) from responding correctly.
I'd recommend debugging your forum by commenting out any custom code you've added to your headers and footers, and disabling all plugins. You should then see this interaction behave as expected. If not, your issue may be theme-related — in which case, you'll need to debug the theme. To do that, save your templates to your computer as a text file, and reset them to default until AJAX behavior is back to normal.
You can then un-comment code, re-enable plugins, and paste back in templates until you see these interactions break. Once you've found the offender, keep it hidden or post for support with that particular issue.
Good luck; debugging isn't always quick or easy. You'll need to take some time to find the root cause of your issues.
This is an AJAX request and is meant to happen without a refresh. Based on your previous threads, I believe you have code somewhere that's preventing this request (and others) from responding correctly.
I'd recommend debugging your forum by commenting out any custom code you've added to your headers and footers, and disabling all plugins. You should then see this interaction behave as expected. If not, your issue may be theme-related — in which case, you'll need to debug the theme. To do that, save your templates to your computer as a text file, and reset them to default until AJAX behavior is back to normal.
You can then un-comment code, re-enable plugins, and paste back in templates until you see these interactions break. Once you've found the offender, keep it hidden or post for support with that particular issue.
Good luck; debugging isn't always quick or easy. You'll need to take some time to find the root cause of your issues.
Um... I tested it on other forums of mine. The [user] liked this pops up automatically but never do the amount of likes change without refresh
It definitely does... Shown here on a theme with minimal changes.
No no no. I'm not talking about that. I'm talking about $[post.likes.total].
Before refresh:
after refresh:
Basically I added $[post.likes.total], and the total only changes after you refresh, but I'd like it to change automatically. I've thought of ways to get by it maybe. For example: if you clicked the likes button on a post an odd number of times, it takes the var of likes total and adds 1 to it, if you clicked it an even number of times, it takes the var of likes total and subtracts 1 from it (except if the even number is 0). This makes it look like it's AJAX, but it really is just an onclick event, which isn't remembered by the system, and it doesn't need to be because once you refresh the page it will stay on that number. Not sure if I'm explaining it well.
Though I'm not sure how to execute this, and I'd prefer if there were an automatic way to do it.
The AJAX payload for post-likes no longer carries the total likes and that was changed at least three years ago but I can't pinpoint when. It was an internal change and and because it was not in wide use generally went unnoticed during a phase where streamlining those behind the scenes data was a big push for Proboard engineers. I recall seeing the change only because I was working on a project in that area at the time. If you view the pb source you can still see remnants of the instruction that wrote to $(".likes-total") but the actual data that it was writing was removed (since no longer available, total can still be calculated via number of names plus remainder in html) but the line was interestingly left in there just in case.
display_like: function(e) { var t = $("#post-" + e) , i = (parseInt($(".likes-total", t).text()), $(".likes-button", t)); proboards.item("post", e) && proboards.item("post", e).liked ? i.show().addClass("liked") : i.show().removeClass("liked") },
You could listen for the AJAX event, count the number from the likes_html property on the payload (number of names plus "x more") then update the number accordingly (note this would be the most accurate way since the onclick method would not be aware if two or more users liked a post within seconds of each other)
edit
Instead of "1 Like", "2 Likes", etc. where you had to click the link to see who the likers were it was changed to be actual display names which means you only sent off an XHR for names if there were more names than could be displayed in that space thus cutting down drastically on unnecessary server usage.
Do not help: 1. Ungrateful people 2. Lazy people 3. Irresponsible person 4. Manipulators 5. Chronic critics 6. Narcissists 7. Opportunists 8. Envious people
"To fight the bug, we must first understand the bug. "
The AJAX payload for post-likes no longer carries the total likes and that was changed at least three years ago but I can't pinpoint when. It was an internal change and and because it was not in wide use generally went unnoticed during a phase where streamlining those behind the scenes data was a big push for Proboard engineers. I recall seeing the change only because I was working on a project in that area at the time. If you view the pb source you can still see remnants of the instruction that wrote to $(".likes-total") but the actual data that it was writing was removed (since no longer available, total can still be calculated via number of names plus remainder in html) but the line was interestingly left in there just in case.
display_like: function(e) { var t = $("#post-" + e) , i = (parseInt($(".likes-total", t).text()), $(".likes-button", t)); proboards.item("post", e) && proboards.item("post", e).liked ? i.show().addClass("liked") : i.show().removeClass("liked") },
You could listen for the AJAX event, count the number from the likes_html property on the payload (number of names plus "x more") then update the number accordingly (note this would be the most accurate way since the onclick method would not be aware if two or more users liked a post within seconds of each other)
Wait. Is that code to help my problem, and where exactly would I put it? (I put it on the bottom on the Post templates in a script tag and it isn't working so I'm wondering where it exactly should go.
Do not help: 1. Ungrateful people 2. Lazy people 3. Irresponsible person 4. Manipulators 5. Chronic critics 6. Narcissists 7. Opportunists 8. Envious people
"To fight the bug, we must first understand the bug. "