I am implementing a site using HTML, PHP and MySQL that allows the user to append a comment to a comment field displayed on the page using a hidden form with onclick activation. The page is rendered from a MySQL database and when the Comment field is appended to the current Comment field in the database associated with that record, I'd like to force a reload not using cache, so that the reload picks up the new Comment addition and keeps the scroll position in the page.
I found a previous post using a script function named "refreshpagekeepPosition" and that works, but the page is being refreshed from cache, so it doesn't pick up the new Comments on the rebuild. I'm a JavaScript novice, so I don't understand most of the function's code, but am hoping that someone out there can help me tweak it to force a non-cached page rebuild. Keeping the current page position is secondary to reloading the page from scratch to pick up the Comment addition. I'll take whatever I can get. Any ideas would be greatly appreciated.
Here is the code:
<script>
function refreshpagekeepPosition() {
document.addEventListener("DOMContentLoaded", function (event) {
var scrollpos = sessionStorage.getItem('scrollpos');
if (scrollpos) {
window.scrollTo(0, scrollpos);
sessionStorage.removeItem('scrollpos');
}
});
window.addEventListener("beforeunload", function (e) {
sessionStorage.setItem('scrollpos', window.scrollY);
});
}
</script>