I send a value to a php
file with AJAX
.
I am having this function in jQuery
:
// Service select change
$container.on('change', '.bookly-js-select-service', function() {
var gekozen_behandeling = this.value;
$.ajax({
type: 'POST',
url: '/behandeling.php',
data: {
behandeling_nieuw: gekozen_behandeling
},
dataType: 'html',
success: function(response) {
console.log(response);
}
});
});
After doing this it alerts done.
In my file behandeling.php
the code is like this:
<?php
session_start();
$_SESSION["type_behandeling"] = $_POST["behandeling_nieuw"];
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
?>
After doing this and navigate to the behandeling.php
file the session variable
is still empty.
<pre>Array
(
[bookly] => Array
(
[forms] => Array
(
[5e1c6d8916b27] => Array
(
[defaults] => Array
(
[service_id] => 0
[staff_id] => 0
[location_id] => 0
[category_id] => 5
)
[last_touched] => 1578921357
[data] => Array
(
[first_rendered_step] => 1
[time_zone] =>
[time_zone_offset] =>
[date_from] => 2020-01-13
[days] =>
[time_from] => 09:00
[time_to] => 21:00
[slots] => Array
(
)
[facebook_id] =>
[full_name] =>
[first_name] =>
[last_name] =>
[email] =>
[email_confirm] =>
[phone] =>
[birthday] =>
[additional_address] =>
[country] =>
[state] =>
[postcode] =>
[city] =>
[street] =>
[street_number] =>
[address_iso] => Array
(
)
[notes] =>
[info_fields] => Array
(
)
[coupon_code] =>
[deposit_full] => 0
[edit_cart_keys] => Array
(
)
[repeated] => 0
[repeat_data] => Array
(
)
)
[cart] => Array
(
)
[chain] => Array
(
[0] => Array
(
[service_id] =>
[staff_ids] => Array
(
)
[number_of_persons] =>
[quantity] =>
[extras] => Array
(
)
[custom_fields] => Array
(
)
[location_id] =>
[series_unique_id] => 0
[first_in_series] =>
[units] => 1
)
)
[booking_numbers] => Array
(
)
[payment_id] =>
[payment_type] => local
)
[5e1c6dc0324c7] => Array
(
[defaults] => Array
(
[service_id] => 0
[staff_id] => 0
[location_id] => 0
[category_id] => 5
)
[last_touched] => 1578921411
[data] => Array
(
[first_rendered_step] => 1
[time_zone] =>
[time_zone_offset] =>
[date_from] => 2020-01-13
[days] =>
[time_from] => 09:00
[time_to] => 21:00
[slots] => Array
(
)
[facebook_id] =>
[full_name] =>
[first_name] =>
[last_name] =>
[email] =>
[email_confirm] =>
[phone] =>
[birthday] =>
[additional_address] =>
[country] =>
[state] =>
[postcode] =>
[city] =>
[street] =>
[street_number] =>
[address_iso] => Array
(
)
[notes] =>
[info_fields] => Array
(
)
[coupon_code] =>
[deposit_full] => 0
[edit_cart_keys] => Array
(
)
[repeated] => 0
[repeat_data] => Array
(
)
)
[cart] => Array
(
)
[chain] => Array
(
[0] => Array
(
[service_id] =>
[staff_ids] => Array
(
)
[number_of_persons] =>
[quantity] =>
[extras] => Array
(
)
[custom_fields] => Array
(
)
[location_id] =>
[series_unique_id] => 0
[first_in_series] =>
[units] => 1
)
)
[booking_numbers] => Array
(
)
[payment_id] =>
[payment_type] => local
)
[5e1c6df9da30f] => Array
(
[defaults] => Array
(
[service_id] => 0
[staff_id] => 0
[location_id] => 0
[category_id] => 5
)
[last_touched] => 1578921468
[data] => Array
(
[first_rendered_step] => 1
[time_zone] =>
[time_zone_offset] =>
[date_from] => 2020-01-13
[days] =>
[time_from] => 09:00
[time_to] => 21:00
[slots] => Array
(
)
[facebook_id] =>
[full_name] =>
[first_name] =>
[last_name] =>
[email] =>
[email_confirm] =>
[phone] =>
[birthday] =>
[additional_address] =>
[country] =>
[state] =>
[postcode] =>
[city] =>
[street] =>
[street_number] =>
[address_iso] => Array
(
)
[notes] =>
[info_fields] => Array
(
)
[coupon_code] =>
[deposit_full] => 0
[edit_cart_keys] => Array
(
)
[repeated] => 0
[repeat_data] => Array
(
)
)
[cart] => Array
(
)
[chain] => Array
(
[0] => Array
(
[service_id] =>
[staff_ids] => Array
(
)
[number_of_persons] =>
[quantity] =>
[extras] => Array
(
)
[custom_fields] => Array
(
)
[location_id] =>
[series_unique_id] => 0
[first_in_series] =>
[units] => 1
)
)
[booking_numbers] => Array
(
)
[payment_id] =>
[payment_type] => local
)
[5e1c6e0f76ddd] => Array
(
[defaults] => Array
(
[service_id] => 0
[staff_id] => 0
[location_id] => 0
[category_id] => 5
)
[last_touched] => 1578921490
[data] => Array
(
[first_rendered_step] => 1
[time_zone] =>
[time_zone_offset] =>
[date_from] => 2020-01-13
[days] =>
[time_from] => 09:00
[time_to] => 21:00
[slots] => Array
(
)
[facebook_id] =>
[full_name] =>
[first_name] =>
[last_name] =>
[email] =>
[email_confirm] =>
[phone] =>
[birthday] =>
[additional_address] =>
[country] =>
[state] =>
[postcode] =>
[city] =>
[street] =>
[street_number] =>
[address_iso] => Array
(
)
[notes] =>
[info_fields] => Array
(
)
[coupon_code] =>
[deposit_full] => 0
[edit_cart_keys] => Array
(
)
[repeated] => 0
[repeat_data] => Array
(
)
)
[cart] => Array
(
)
[chain] => Array
(
[0] => Array
(
[service_id] =>
[staff_ids] => Array
(
)
[number_of_persons] =>
[quantity] =>
[extras] => Array
(
)
[custom_fields] => Array
(
)
[location_id] =>
[series_unique_id] => 0
[first_in_series] =>
[units] => 1
)
)
[booking_numbers] => Array
(
)
[payment_id] =>
[payment_type] => local
)
)
)
[type_behandeling] => 51
)
</pre>
2
Answers
Check the $_POST Value
It might be possible that when you navigate to
behandeling.php
that you are assigning the posted variable to session as
the posted data not found as you are visiting (http get method). Hence session is overwritten with null or empty.