Best Jquery ,javascript, HTML5 CSS3 tutorial with jquery examples, php script , demos for beginners, web designers and web developers.


Jquery Training

Jquery training blog

Ajax post with jquery and php

The basic example of Ajax post is $.ajax({variable:value, variable:value, … })

AJAX stands for Asynchronous JavaScript and XML. AJAX Post used to create faster, and more interactive web applications using javascript, XML. Alternatively we can say that, using ajax, we can exchange data or update of a small portion of web page without reloading the page.

In AJAX post , when we hit submit button, JavaScript makes a request to the server and interpret the results.After manipulating the result it updates the current screen.

Basic Ajax post format

    url: 'url of the function to intract ',
    dataType: 'json',
    type: 'post',
    contentType: 'application/json',
    data: JSON.stringify( { "nae": $('#name').val(), "mobile": $('#mobile').val() } ),
    processData: false,
    success: function( data, textStatus, jQxhr ){
        $('#response').html( JSON.stringify( data ) );
    error: function( jqXhr, textStatus, errorThrown ){
        console.log( errorThrown );

In the below example, we are going to describe, how to make Ajax post  with PHP.

<!DOCTYPE html>
<script src=""></script>

border: 1px solid #06ab31;
padding: 5px;
margin-bottom: 1em;
background: #d1e2c4;
text-align: center;
border: 1px solid #ba5e00;
padding: 5px;
margin-bottom: 1em;
background: #ffc0ae;
text-align: center;
margin-left: 40%;
margin-top: 10%;
border: 1px solid;
width: 25%;
text-align: center;

<div id="form-block">
<div id="msg"></div>
<form method="post" name="postForm">
<div class="element-block">
<label>User name</label>
<input type="text" name="username" id="username" placeholder="Type user name">
<input type="button" value="Submit" id="submit" />
$(document).ready(function() {
$('#submit').click(function(event) {
var postForm = {
'username' : $('input[name=username]').val()
type : 'POST',
url : 'execute.php',
data : postForm,
dataType : 'json',
success : function(data) {



},error: function(data) {


The execute.php file


$errors = array();
$data = array();

if (empty($_POST['username'])) {
$errors = 'User name cannot be blank';

if (!empty($errors)) {
$data['success'] = false;
$data['msg'] = $errors;

else {
$data['success'] = true;
$data['msg'] = 'Record inserted Successfully';

echo json_encode($data);

About the author

Joydeb Choudhury holds a Master's degree in Computer Application from I.G.N.O.U. After working as a web developer in various companies he has started bloging in 2016.

Recent Posts of blog

Downalod Free Php Scripts