Through AJAX
As far as I am aware there is no way to force Safari to resend the POST data during a refresh. The only way to 'fix' this issue is to separate the logic from the document in which the result is displayed. What I mean by this in practical terms is that you could trigger the logic you want from code using an AJAX request, whilst the document itself will be a (relatively) dumb page.
So what you would get is:
POST document.ext
#In whatever server side language you're using, the reason this can't be done
# purely in javascript is that POST data is only available to the server.
print "<script>"
print "POSTdata = " + JSONEscape(POSTdata) + ";"
print "var doAction = function(){"
print " ajax('action.ext', POSTdata, function(result){});"
print "});"
print "</script>"
print "<button onclick='doAction()'>Refresh</button>"
POST action.ext
# all the logic you previously had in document.xxx
The result of this is:
- In all browsers a user initiated refresh will send the
POST
data and the logic is re-triggered.
- The refresh button will at all times re-trigger your logic directly without reloading the entire page.
Self-submitting form
It just hit me that another - easier to implement - way to achieve this is to simply create a <form action='?' method='POST'>
and in code trigger it's submit
function. You would still need to print
the POSTdata
, but instead of trigger an Ajax call, you would simply trigger a redirect to the same page through the hidden <form>
. The advantage of this is that it doesn't require any restructuring, though I personally think the AJAX method would look neater. A quick Google-fu showed these answers detailing the procress.