Skip to content Skip to sidebar Skip to footer

Staying In The Same Page Without Refreshing It After Adding To Database

I have PHP web page where I need to insert some information to my database. When insert is done, it refresh the same page. But I've been told that this process is not practical bec

Solution 1:

Add preventDefault to your javascript function

    Function(e){
    e.preventDefault()
    ...

}

Solution 2:

In your HTML file you have action = 'insert.php' in <form> tag and you are also calling a function on buttonclick having idinsert.

Both are doing the same thing - sending values from HTML page to insert.php. In case <form>, page gets refreshed so go for ajax. Keep the script for click event.

  1. Remove action="insert.php" and method="post" from <form> tag.
  2. Change type = "button" in <button> tag.

Hope this will help.

Post a Comment for "Staying In The Same Page Without Refreshing It After Adding To Database"