Save html form using ajax without page refresh
Posted in: Jquery, PHP

Save Html Form Using Ajax and PHP Without Page Refresh

Hello friends hope you all are doing good and please be safe at your home in this pandemic situation.

Usually we use to save our html forms using our server side language but these days no body want to refresh the page after clicking the submit button. As it took much time to reload the page again and also it consumes more bandwidth of the server. To overcame from this situation now we use Ajax or Jquery  to submit the form. In this tutorial i will show you how you can save html form using Ajax and php without page refresh. If you want to save form using php then read it here.

First of all we will divide it into 3 parts 1 is HTML form and 2nd is Ajax for getting the values and final is PHP part to get the values and save it to the database. Now we will start our working from 1st part which is creating HTML form.




I am not including any kind of stylesheet so  please add it at your end or copy the bootstrap design and Scripts from below. You can use any version as i m giving you the outlook only.

HTML Form (Use bootstrap for this)

In the above code we have created the HTML form for filling out the data. Now we will written down the Ajax part to transfer this data to our PHP page.

Ajax Script

In the above code you can see that we are transferring our data to our PHP page you can see the url variable. In the “data” variable we are getting our whole form values. We have used the post method so we will transfer the data using POST to our PHP so while getting the data we have to use $_POST in our PHP.

PHP Script (postvalues.php)

Hope you like our tutorial if you have any advice then please comment below.

~ Stay Home Be Safe Use Mask ~

 

Leave a Reply

Your email address will not be published. Required fields are marked *