Staying in the same page without refreshing it after adding to database

后端 未结 2 1022
挽巷
挽巷 2021-01-27 12:59

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

相关标签:
2条回答
  • 2021-01-27 13:21

    Add preventDefault to your javascript function

        Function(e){
    
        e.preventDefault()
    
        ...
    
    }
    
    0 讨论(0)
  • 2021-01-27 13:24

    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.

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

    Hope this will help.

    0 讨论(0)
提交回复
热议问题