ether ether - 1 year ago 43
Javascript Question

Stopping a refresh/redirect on form submission

I have an app that wants to redirect after submitting and I would like to freeze it after clicking submit. The app is a multiform that has an end slide that I would like the animation to trigger and then freeze it from redirect/refresh.

<form id="form" class="msform hs-form stacked hs-custom-form" accept-charset="UTF-8"
action="confidential-url" enctype="multipart/form-data" method="POST" novalidate="">

<!-- form stuff -->


$(".submit").click(function () {
return true;

I have tried adding
onSubmit="return false"
to my
tag as well as various
methods. All of them will either:

• Cause it to prevent the redirect/refresh but not update the fields in the DB

• Update fields but page will still redirect

After trying to do this in AJAX I found out that I was being blocked out from the external URL, thanks to to r4phG for helping me figure it out!

Answer Source

Is your submission causing your redirection/ refresh ?

If you have to submit your form to update fields in your database, you'll have to submit your form. But if you don't want to refresh all your page, you should think of using Ajax, as your submission will not refresh your page

Example from jquery ajax doc : $("#form").submit(function() { $.ajax({ url:'confidential-url', method:'POST' , data:$(this).serialize() //submits your form information }); return false; // prevent the server form submission });

jQuery ajax documentation