Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Submit The Form Without Page Refresh Using Ajax And jQuery.

Tuesday, Apr 4, 2017

Tags:- Ajax JavaScript jQuery PHP

In this tutorial we will teach you how to submit the form without page refresh and then insert the data into database using Ajax and jQuery.You only need to download jQuery to submit the form without page refresh.You may also like jQuery form validation.

Submit Form without page refresh

To Submit the form without page refresh it takes only two steps:-

  1. Make a HTML form to submit the data
  2. Connect to the database and store data

Step 1.Make a HTML form to submit the data

We make a HTML form with post method and save it with a name senddata.html

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">

function submitdata()
 var name=document.getElementById( "name_of_user" );
 var age=document.getElementById( "age_of_user" );
 var course=document.getElementById( "course_of_user" );

  type: 'post',
  url: 'insertdata.php',
  data: {
  success: function (response) {
   $('#success__para').html("You data will be saved");
 return false;


<form method="POST" onsubmit="return submitdata();">
 <input type="text" name="username" id="name_of_user">
 <input type="text" name="userage" id="age_of_user">
 <input type="text" name="usercourse" id="course_of_user">
 <input type="submit" name="submit_form" value="Submit">

<p id="success_para" ></p>


You can do validation to make your code more secure or you can view our How to do validation before and after submitting the form tutorial.

Step 2.Connect To The Database and Store Data

In this step we get all the data which get get from senddata.html page and store them in database.

// insertdata.php


if( isset( $_POST['user_name'] ) )

$name = $_POST['user_name'];
$age = $_POST['user_age'];
$course = $_POST['user_course'];

$host = 'localhost';
$user = 'root';
$pass = ' ';

mysql_connect($host, $user, $pass);


$insertdata=" INSERT INTO user_info VALUES( '$name','$age','$course' ) ";


That's all, this is how to submit the form without page refresh. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH