How do i stop the form from reloading using Javascript?

后端 未结 5 1138
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 15:18

When a User Submits the form i want to stop the default behavior of the form. ie it should not reload. so that i can perform the AJAX request.

here is the code i use

5条回答
  •  一个人的身影
    2020-12-01 15:53

    Using jQuery:

    $('form').on('submit', function() {
      // call functions to handle form
      return false;
    });
    

    Basically the same as the above solutions, but I prefer to keep my JS out of my HTML, even the "onsubmit" attribute.

提交回复
热议问题