dongliang1996 2014-08-17 15:55
浏览 71
已采纳

如何使用PHP AJAX Jquery将javascript警报和消息传递到主页面?

I'm having a problem getting the message using the 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.

The Main Page is reservation.php

When the condition is not met it should echo a javascript alert in the reservation.php

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

<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

$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!

  • 写回答

1条回答 默认 最新

  • doutandusegang2961 2014-08-17 16:00
    关注

    Try by changing your scripts something like below

    In getdate.php

    if(strtotime($format) <= strtotime(date("Y-m-d",strtotime('+7 days')) ))
    {
        echo 'invalid';
    }
    

    In 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);
            }
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?