当用户登录时,我将电子邮件存储在 $email 中(我也尝试过全局 $email)。然后我有一个表格,他们可以在其中输入室友的名字来搜索已经安排好的约会。
AJAX
$("#reserveAPickupAppointmentForm3").submit (function() {
roommate = $("#roommate").val();
$.post('roommateSearch.php', 'val=' + roommate, function (response) {
$("#roommateResults").html(response);
});
return false;
});
在roommateSearch.php上,如果找到约会,您可以点击该约会同时为自己安排一个约会。然后我获取该信息并将其发布到位于 postAppointment.php 的另一个处理页面,以便我可以将其插入数据库中。
$(".confirmAppointment").click (function() {
$(".confirmAppointment").unbind("click");
var location = $(".reserveAPickupAppointmentLocation", entry).text();
var subLocation = $(".reserveAPickupAppointmentSubLocation", entry).text();
var startTime = $(".reserveAPickupAppointmentStartTime", entry).text();
var endTime = $(".reserveAPickupAppointmentEndTime", entry).text();
var date = $(".reserveAPickupAppointmentDate", entry).text();
alert (location + subLocation + startTime + endTime + date);
$.post("postAppointment.php", "location=" + location + "subLocation=" + subLocation + "startTime=" + startTime + "endTime=" + endTime + "date=" + date, function (response) {
alert (response);
});
});
但是,为了正确创建约会,我需要重新捕获用户的电子邮件并将其添加到 SQL 语句中。但是,当我在 postAppointment.php 上调用 $email 时,什么也没有显示。我该怎么做?
我曾考虑过将其作为隐藏输入文本框包含在原始表单中,并以 $email 作为值,然后将该信息与其余部分一起传递,但肯定有一种更简单的方法......我'我希望有一种方法可以让 postAppointment.php 识别 $email。
最佳答案
当用户成功登录时,将他的电子邮件 ID 保存在 session 变量中。您可以在 ajax 处理页面中访问此变量值。
检查您访问session变量的页面是否添加了“php session_start()
”。
关于javascript - 在 AJAX 处理页面上调用 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8632448/