java - What is best practice to prevent double form submit -
recently working on project using ajax call java servlet, , request takes more 10 sec response, need make sure during time user won't able submit form again, , current approach detect submit button click event , disable submit button, once success or error function triggered in ajax, enable button again, not approach.
---- edit ---- sorry, wasn't explain clearly, mean can stop non technical background user, if 1 intend attack site or whatever reason, can modify html code enable button, , submit,
before tried way set cookie interval after form submit, , check cookie when request finish, wondering whether there other way this, question purely learning purpose.
sorry english:)
i dont see wrong disabling button, use, because not provides indication system acknowledged click prevent user clicking again.
if reason dont can disable underlying method call this:
var issubmitting = false; function handleclick(){ if (!issubmitting) { issubmitting = true; $.ajax( "http://yourservice/submit" { data: {somedata:123}, contenttype: 'application/json', type: 'post', success: function(){ issubmitting = false; }, }); } }
about edit, cookie sounds approach, need server going pass client, , check on submit. once has been authorized server prevent processing of further requests same parameter.
but bear in mind malicious user spawn thousands of requests cookies , perform submissions anyway, not defence against attackers, have implement form of throttling.
so in end if want prevent accidental submissions button hide suffice.
Comments
Post a Comment