TestProject Forum
Powered by leading experts in the test automation community

Stop jQuery Ajax POST from sending twice

I have a simple html login form which I submit to my server via ajax POST request after the form is filled.

But every time I submit the form the POST is sent twice or too fast to notice in the network tab (in chrome tools).

What prompts this behavior ?

If your form has a submit button and an Ajax POST call afterwards then the you might be sending POST request twice.

To stop this behavior you could use the event parameter (passed in as argument to form submit jQuery function) in order to prevent the submit of the form.

$('#myForm').submit(function(event) {
    event.preventDefault();    // avoid to execute actual form submit.

    $.ajax({ 
    / ...
}

thanks for your input Ruhit

I tried using the submit event that you posted

I tried with the type=“submit” on my element and without

still not working for me :frowning:

not sure what I did wrong