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:

  1. chrome network tab in dev tools shows 2 requests, , http options request successful http 200 , single http post expected payload containing transaction id
  2. console log "test" twice
  3. wireshark shows http options, , 2 http post requests.
  4. 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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -