dst2017 2018-12-18 23: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-18 23: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部