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 button
click
having id
insert
.
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.
- Remove
action="insert.php"
andmethod="post"
from<form>
tag. - 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"