I’m afraid it’s not simple at all. getElementById() is the correct method, but only one element on a page should have a particular ID. You need multiple calls to handle multiple elements. getElementsByName() requires a different handling strategy.
The actual problem is the AJAX calls are not being processed correctly. AJAX in WordPress does not work like it would in any other environment. First of all, IMO, attempting AJAX without jQuery is going to result in some failures due to erratic browser support. Then in WordPress, all AJAX calls should be routed through wp-admin/admin-ajax.php. The actual processing is then implemented by hooking into a particular action that is fired by admin-ajax.php. Failure to do AJAX through admin-ajax.php will result in erratic behavior.
I am not saying your plugin will not work, only that it will not work consistently, as you have seen. To work consistently, IMO, the entire strategy of implementing AJAX needs to be revisited. Sorry to be the bearer of bad news, keep in mind this is all solely my opinion, you can probably find differing opinions.
(@elsnare)
10 years, 11 months ago
This is probably a simple problem, but I’m not familiar with JS. I’m using WordPress with a comment rating plugin to display 2 loops of comments – 1 sorted by “thumbs” rating, and second with standard order.
The problem:
When a thumb is clicked next to a comment in the standard section the vote is added to the comment in the rating section – since it’s called first in code on the site. The standard section rating box is not being updated until page refresh.
What is expected:
When a vote is clicked, the rating for the same comment should be updated in both rating and standard loops sections.
What I did:
After some research i determined that document.getElementsById does not continue after first ID is found. Replaced it with getElementsByClassName and added classes to the html. But now nothing does update 🙂 Any ideas?