insert query with ajax without reloading whole page

后端 未结 2 1558
遇见更好的自我
遇见更好的自我 2021-01-24 04:51

I want to insert data through AJAX (without reload page). I tried but it is not showing data and also reload page.

I have a file first.php (in which, fo

2条回答
  •  暖寄归人
    2021-01-24 05:52

    The submit button will automatically reload the page on click so the solution is either change the button type to button or add preventDefault to the click event

    $("#submit1,#submit2").click(function() {
      alert('form submited')
    })
    $("#submit3").click(function(e) {
      e.preventDefault();
      alert('form submited')
    })
    
    
    this will reload the page
    this will not reload the page
    this will not reload the page

提交回复
热议问题