Browser: Prevent POST data resubmit on refresh using only JavaScript

Viewed 7656

I am aware of the many Post/Redirect/Get questions on here. This one is a bit different. I'm unable to find an answer that explains this particular JavaScript solution.

When you submit a form via POST and then hit the refresh button afterwards, the browser will prompt me to re-submit data. HOWEVER this prompt does not happen in the WordPress backend (when JS is enabled) and there is no Redirect/Get after the Post.

I've tried to show this in a series of screenshots below. It shows the first POST submit with the POST data printed on the page, and then the refresh causes a GET without any browser re-submit prompt.

browser resubmit without post

When I disable JavaScript and hit refresh, I get the expected "Would you like to resubmit your data?" prompt and the refresh causes a second POST.

js disabled, normal post resubmit happens

So wordpress is doing some JavaScript magic here to prevent POST data resubmission on refresh/back button.

Can anyone point me to the code in WordPress that shows how they achieve this using only JavaScript? I have no idea where to even start searching.

Do they do something with the pushstate?

Thanks!

1 Answers
Related