[英]How can I pass the javascript alert and message into the main page using PHP AJAX Jquery?
I'm having a problem getting the message using the Ajax jquery. 我在使用Ajax jQuery获取消息时遇到问题。 I'm trying to validate the Date.
我正在尝试验证日期。 The date should not accept previous dates and accept the dates after 7 days of the current date.
该日期不应接受以前的日期,而应接受当前日期后7天之后的日期。
The Main Page is reservation.php 主页是Reservation.php
When the condition is not met it should echo a javascript alert in the reservation.php 当不满足条件时,应在Reservation.php中回显一个JavaScript警报。
echo ("<script language='Javascript'> alert('Preferred Date Is Not Allowed!')</script>");
If the condition is met it should echo a message 如果满足条件,则应回显一条消息
echo "<img src='img/information.png' style='width:30px;height:30px;'/><i style='color:yellow;'>No. of passengers on " . $format . ": " . $totalpass . ' </i><br>';
This is my Code: Reservation.php 这是我的代码:Reservation.php
<script type="text/javascript">
$(document).ready(function() {
$("#date").change(function() {
$.get('getdate.php?parent_cat=' + $(this).val(), function(data) {
$("#sub_cat2").html(data);
});
});
});
</script>
<input class="form-control datepicker" name="r_date" id="date" type="text" placeholder="reservation date">
<div id="subcat2"> </div>
getdate.php getdate.php
$parent_cat = $_GET['parent_cat'];
if(strtotime($format) <= strtotime(date("Y-m-d",strtotime('+7 days')) ))
{
echo ("<script language='Javascript'> alert('Preferred Date Is Not Allowed!')</script>");
}
else
{
echo "<img src='img/information.png' style='width:30px;height:30px;'/><i style='color:yellow;'>No. of passengers on " . $format . ": " . $totalpass . ' </i><br>';
}
Kindly help me please Thank you! 请帮助我,谢谢!
Try by changing your scripts something like below 尝试通过更改脚本,如下所示
In getdate.php 在getdate.php中
if(strtotime($format) <= strtotime(date("Y-m-d",strtotime('+7 days')) ))
{
echo 'invalid';
}
In Javascript 用JavaScript
$("#date").change(function() {
$.get('getdate.php?parent_cat=' + $(this).val(), function(data) {
if(data == 'invalid'){
alert('Preferred Date Is Not Allowed!');
}else{
$("#sub_cat2").html(data);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.