I am trying to use the data that AJAX sends in PHP but for some reason says that the array is empty I also don't get any errors from PHP or in my console. the console.log(data) shows the array with with the values of the selects. After the PHP there is HTML where the script.js is.
console.log
index.php
<?php
error_reporting(-1);
$value1 = "";
$value2 = "";
print_r($_POST);
if (isset($_POST['date']) && isset($_POST['date'])) {
if (isset($_POST['date'])) {
echo "Yes, mail is set";
$value1 = $_POST['date'];
$value2 = $_POST['quantity'];
} else {
echo "No, mail is not set";
}
exit;
}
echo $value1;
echo $value2;
$canmakereservation = "https://www.planyo.com/rest/?method=can_make_reservation&api_key=YOURKEY&resource_id=110556&start_time=2018-04-25 09:00&end_time=2018-04-25 12:00&quantity=5";
$cleancanmakereservation = preg_replace("/ /", "%20", $canmakereservation);
$reservationavailable = file_get_contents("$cleancanmakereservation");
$reservationAvailable = json_decode($reservationavailable, true);
// echo "$cleancanmakereservation";
// var_dump($reservationAvailable);
?>
script.js
$(document).ready(function(){
var date = "date";
var begin = "begin";
var eind = "eind";
var aantal = "aantal";
$('#datum').change(function() {
date = $("#datum").val();
console.log(date);
});
$('#beginTijd').change(function(){
begin =( $(this).val() );
console.log(begin);
});
$('#Tijdsduur').change(function(){
eind =( $(this).val() );
console.log(eind);
});
$('#aantalSloepen').change(function() {
aantal = ($(this).val());
console.log(aantal);
$.ajax({
type: "POST",
url: "index.php",
data: {
date: begin,
quantity: aantal
},
success: function(data) {
alert(data);
console.log(data);
}
});
});
});


exit;in index.php stop the code?if (isset($_POST['date']) && isset($_POST['date'])) {you should probably be testing$_POST['quantity']rather than testingdatetwiceshows empty? I can clearly see the output of thevar_dump()in your console output.dateandquantityfrom your console imagejson.echo. andreturnare equivalent. So it cannot be faulted with string ! except other variable type