dst2017 2018-12-19 07:23
浏览 87
已采纳

当我在ajax中传递jquery datepicker日期时,php会发现索引错误

Here is my demo.php

<div class="form-message"></div>
<div class="input-group date" data-provide="datepicker">
    <input class="form-control" id="datepicker" name="ownerBdate" placeholder="Enter your Bday" type="text" data-date-end-date="0d" autocomplete="off"  required=""/>
    <label class="ownerBdayLabel">Birthday</label>
    <div class="input-group-addon">
        <span class="zmdi zmdi-calendar"></span>
    </div>
</div>
<div class="container-login100-form-btn">
    <div class="wrap-login100-form-btn">
        <div class="login100-form-bgbtn"></div>
        <button id="submit" class="login100-form-btn">Register</button>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $("#dateBirthday").datepicker({
            dateFormat: "dd-mm-yy",
            changeYear: true
    });
        $("#submit").click(function(event){
            event.preventDefault();
            var ownerBdate = $("ownerBdate").val();
            $(".form-message").load("demo-validator.php",{
                ownerBdate : ownerBdate,
            submit : submit
            });
        });
    });
</script>

here is the demo-validator.php

<?php 
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
    include_once 'includes/dbh.inc.php';
    $ownerBdate = $_POST['ownerBdate'];
    echo $ownerBdate;

?>

Problem is when I click submit button it gives me an error where it says undefined index in my php. I have tried all the way I can.

  • 写回答

3条回答 默认 最新

  • dqmnueuu459279 2018-12-19 07:39
    关注

    Please change code to use id instead of name var ownerBdate = $("ownerBdate").val(); and

    var ownerBdate = $("#dateBirthday").val(); // check with console or alert value coming or not. 
    

    you are not getting selected date value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥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,如何解決?