javascript - Chrome auto re-submits HTTP POST -
i have angular 1.x application doing http post api. if api takes longer 3-5 seconds process request, chrome submitting second request before first finished, causing api attempt process same request twice.
looking @ chrome dev tools, shows 1 request wireshark shows 2 http post requests same endpoint.
i've far been unable find documentation on behavior.
has else ran or found information how control it?
edit add code sample
html ng-click
<span><i class="fa fa-refresh" ng-click="resubmit(transaction.transid)"></i></span>
angular controller function
$scope.resubmit = function(transid) { remediationservice.resubmit(transid).then(function(data) { init(); }); };
angular service function
self.resubmit = function(id) { return $http.post(api + '/remediation/resubmit/', { transid: id }); };
currently using test handler server side using hapijs in node cause issue forcing 10 second delay.
resubmit = async function(request, reply) { console.log('test'); settimeout(function(){ reply({message:"success"}) }, 10000) }
after of above code executed, here see:
- chrome network tab in dev tools shows 2 requests, , http options request successful http 200 , single http post expected payload containing transaction id
- console log "test" twice
- wireshark shows http options, , 2 http post requests.
- after 10 seconds up, single http post request in chrome shows successful success message.
edit 2 - cors handling
this have in place handle cors , options preflight request:
server.route({ method: 'options', path: '/{p*}', config: { handler: function(request, reply) { var response = reply(); response.headers['access-control-allow-headers'] = 'content-type, authorization'; response.headers['access-control-allow-methods'] = 'get, post, put, delete, options'; return response; }, cors: true } });
Comments
Post a Comment