Php jquery ajax post request example

Php jquery ajax post request example

In this post we will give you information about Php jquery ajax post request example. Hear we will give you detail about Php jquery ajax post request exampleAnd how to use it also give you demo for it if it is necessary.

In this example, i will share with you how to write simple ajax request example with jquery php. we will see jquery ajax post data example with php. you can simply form submit with pass ajax post data and get return all data with success.

I will give you very simple example of ajax post request with php. you can also write server side validation using php logic. you can also pass form serialize ajax data to post method with php.

After this example you can easily write Ajax Get Request, Ajax Post Request, Ajax Put Request and Ajax Delete Request with jquery ajax and php.

You need to just follow bellow step to create ajax post request:


<!DOCTYPE html>



<title>Php Ajax Form Validation Example</title>

<script type="text/javascript" src=""></script>

<link rel="stylesheet" href="">



<div >

<h1>Php Ajax Form Validation Example</h1>

<form role="form" id="contactForm" data-toggle="validator" >

<div style="display: none">


<div >

<div >

<input type="text" id="name" placeholder="Name">



<div >

<div >

<input type="email" id="email" placeholder="Email" >



<div >

<div >

<input type="text" id="msg_subject" placeholder="Subject" >



<div >

<div >

<textarea id="message" rows="7" placeholder="Massage" ></textarea>



<button type="submit" id="submit" ><i ></i> Send Message</button>




<script type="text/javascript">

$(document).ready(function() {



var name = $("#name").val();

var email = $("#email").val();

var msg_subject = $("#msg_subject").val();

var message = $("#message").val();


type: "POST",

url: "/formProcess.php",

dataType: "json",

data: {name:name, email:email, msg_subject:msg_subject, message:message},

success : function(data){

if (data.code == "200"){

alert("Success: " +data.msg);

} else {












$errorMSG = "";

/* NAME */

if (empty($_POST["name"])) {

$errorMSG = "<li>Name is required</<li>";

} else {

$name = $_POST["name"];


/* EMAIL */

if (empty($_POST["email"])) {

$errorMSG .= "<li>Email is required</li>";

} else if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {

$errorMSG .= "<li>Invalid email format</li>";

}else {

$email = $_POST["email"];



if (empty($_POST["msg_subject"])) {

$errorMSG .= "<li>Subject is required</li>";

} else {

$msg_subject = $_POST["msg_subject"];



if (empty($_POST["message"])) {

$errorMSG .= "<li>Message is required</li>";

} else {

$message = $_POST["message"];



$msg = "Name: ".$name.", Email: ".$email.", Subject: ".$msg_subject.", Message:".$message;

echo json_encode(['code'=>200, 'msg'=>$msg]);



echo json_encode(['code'=>404, 'msg'=>$errorMSG]);


You can quick run our example by following command, so run bellow command for run PHP project.

php -S localhost:8000

Now, you can check from your url by bellow URL:

Also see:PHP – Bootstrap autocomplete tokenfield with Ajax Example

I hope it can help you….

Hope this code and post will helped you for implement Php jquery ajax post request example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

12  +    =  13

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US