close

How to prevent page from reloading after form submit – JQuery

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error How to prevent page from reloading after form submit – JQuery in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How to prevent page from reloading after form submit – JQuery Error Occurs?

How To Solve prevent page from reloading after form submit – JQuery Error ?

  1. How To Solve prevent page from reloading after form submit – JQuery Error ?

    To Solve prevent page from reloading after form submit – JQuery Error Disadvantage: subverts default form behavior, especially when JS is disabled. What if the user wants to hit “enter” to submit?

  2. How to prevent page from reloading after form submit – JQuery

    To Solve prevent page from reloading after form submit – JQuery Error Disadvantage: subverts default form behavior, especially when JS is disabled. What if the user wants to hit “enter” to submit?

Solution 1

The <button> element, when placed in a form, will submit the form automatically unless otherwise specified. You can use the following 2 strategies:

  1. Use <button type="button"> to override default submission behavior
  2. Use event.preventDefault() in the onSubmit event to prevent form submission
  • Advantage: simple change to markup
  • Disadvantage: subverts default form behavior, especially when JS is disabled. What if the user wants to hit “enter” to submit?

Insert extra type attribute to your button markup:

<button id="button" type="button" value="send" class="btn btn-primary">Submit</button>

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment