I have this jquery in another processing.js file and is included in the html file having the form
$("#1st_submit").on("click", function(event) {
var ServiceType = $("#ServiceType").val();
var locality = $("#locality").val();
$.ajax({
type: "POST",
url: 'http://localhost/revamp/booking.php',
data: {
ServiceType: ServiceType,
locality: locality
},
error: function(req, err){ console.log('my message ' + err); },
success: function (data) {
$("#1st_booking_form").hide();
$("#2nd_booking_form").show();
console.log(data);
alert("success");
}
});//ajax
})
In the PHP code, I am accessing the POST variables as
$ServiceType = $_POST['ServiceType'];
$locality = $_POST['locality'];
But I am not getting the POST values in the PHP, It's null
HTML Code with the form is this way
<form role="form" method="post" id="1st_book" action="">
<div class="row" id="1st_booking_form">
<div class="col-md-12 col-sm-12">
<input class="inputMaterial" id="ServiceType" type="text" value="<?php echo $service_name_s; ?>" name="ServiceType" required>
</div>
<div class="col-md-12 col-sm-12">
<input class="inputMaterial" id="locality" type="text" value="<?php echo $locality_s; ?>" name="locality" required>
</div>
<br>
<center><button type="button" class="btn_full" id="1st_submit"> Book Now </button></center>
</div>
</form>
The whole code is working with type:"GET".
print_r($_POST)in php file.