脚本宝典收集整理的这篇文章主要介绍了PHP变量在后续的AJAX调用中返回“default”,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
if(isset($_POST['BookingTime'])){ $bookingTime = $_POST['bookingTime']; $bookingDate = $_POST['theDate']; $dbDateTime = $bookingDate." ".$bookingTime; echo json_encode($dbDateTime); exIT; } if(isset($_POST['bookingPwd'])){ $pwd = $_POST['txtBookingPwd']; //Get the $dbDateTime VARiable??? echo $pwd; }
$dbDateTime变量被设置为对AJAX请求的响应,并且返回jquery很好,但我需要变量用于数据库查询.如何在其他if语句中使用该变量?在我对PHP的理解中,我觉得我遗漏了一些非常基本的东西.我试过全局,但没有运气.
更新
删除出口没有区别. $dbDateTime变量仍未显示在第二个if语句中.这是我运行测试的PHP代码:
if(isset($_POST['bookingTime'])){ $bookingTime = $_POST['bookingTime']; $bookingDate = $_POST['theDate']; $dbDateTime = $bookingDate." ".$bookingTime; // echo json_encode($dbDateTime); // exit; } if(isset($_POST['bookingPwd'])){ $pwd = $_POST['txtBookingPwd']; //Get the $dbDateTime variable??? echo $dbDateTime; echo $pwd; $booking->newBooking($dbDateTime,$pwd); }
该变量是从AJAX请求设置的,其中从HTML表中获取时间值.然后打开一个模态,供用户输入他/她的密码,以便在选定的时间预订法庭.我想也许PHP不存储值,因为变量是在不同的操作中设置的?
第二次更新
会话有效,但尝试通过下一个AJAX调用传递$dbDateTime的值.这是jQuery代码:
var bookingTime; var dbDatetime; $('.courtBook').click(function() { // Find the row var $row = $(this).closest('tr'); // Find the text var bookingTime = $row.find('.courtTime').text()+":00"; var theDate = $('#theDate').text(); $.ajax({ url: 'index.PHP?page=booking',tyPE: 'POST',dataType: 'json',data: {'bookingTime': bookingTime,'theDate': theDate},success: function(data){ var dbDatetime = data; alert(dbDatetime); },error: function(){ alert('Much wrong,such sad'); } }); }); $('#BTnBookingPwd').click(function(){ console.LOG(bookingTime); console.log(dbDatetime); });
在最后一次单击功能中,变量未定义.那么,这在jQuery中如何工作?
以上是脚本宝典为你收集整理的PHP变量在后续的AJAX调用中返回“default”全部内容,希望文章能够帮你解决PHP变量在后续的AJAX调用中返回“default”所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。