【发布时间】:2020-04-30 04:56:57
【问题描述】:
我用AJAX 向php 文件发送一个值。
我在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);
}
});
});
执行此操作后,它会发出警报。
在我的文件behandeling.php 中,代码是这样的:
<?php
session_start();
$_SESSION["type_behandeling"] = $_POST["behandeling_nieuw"];
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
?>
完成此操作并导航到 behandeling.php 文件后,session variable 仍然为空。
<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>
【问题讨论】:
-
您收到警报了吗?没有任何异常?
-
如何将变量存储到会话中?
-
尝试警报(响应);并在此处提供
-
将其设为
console.log并将结果粘贴在其下方。它在type_behandeling中显示了正确的值,但它是一个预订表格,所以在下一步中我需要再次获得该值。我怎样才能做到这一点?导航到第 2 页时页面未刷新 -
要填写
Session或Cookie,您必须使用return。您可以使用return response();,然后在会话中填写您的捐赠数据。
标签: php jquery ajax session post