简体   繁体   English

PHP无法获取发送的Ajax数据

[英]PHP can't get ajax data sent

I'm using jquery multiple date picker and when I send the dates selected by the user to another .php page, I get the error : undefined index : dates. 我正在使用jquery多个日期选择器,当我将用户选择的日期发送到另一个.php页面时,出现错误:未定义的索引:日期。 Here is my code: 这是我的代码:

<form action="../target.php" method="POST" id="form">
    <div id="datedisp"> //the div where the date picker is
    </div>
    <p class="set_disp_p"><input type="submit" id="submit" name="submit" value="Send" /></p>
</form>

And the javascript: 和javascript:

 $("#form").click(function(){
            var dates_value = $('#datedisp').val();
            $.ajax({
                type: 'POST',
                url: '../target.php',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    dates : dates_value,
                },
                });    
        });

And finally,the php from the target.php file 最后,来自target.php文件的php

$dates = $_POST['dates'];
if (isset($dates)) {
    echo "OK";
}

And the calendar: 和日历:

$(function() {
        var dateToday = new Date();

        var disable_array = new Array();

        $("#datedisp").multiDatesPicker({
            minDate: 0,
            maxDate: 365,
             onselect: function(add_array){
                arrayDates.push($('#datedisp').val());
            },
            beforeShowDay: function(date) {
                var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
                return [disable_array.indexOf(string) == -1]
            },
            monthNames: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
            dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
            firstDay: 1,
            dateFormat: "dd/mm/yy"

        });          });

The error is on the target.php page. 错误在target.php页面上。

Does anyone can help me? 有人可以帮助我吗? Thank you very much 非常感谢你

This is the complete code: 这是完整的代码:

<form action="../target.php" method="POST" id="form">
<div id="datedisp"> //the div where the date picker is
    <input id="datedisp_input" >
</div>
<p class="set_disp_p"><input type="submit" id="submit" name="submit" value="Send" onclick="return false;"/></p>

And the javascript: 和javascript:

<script type="text/javascript">
$("#submit").click(function(){        

    var dates_value = $('#datedisp_input').val();

     $.ajax({
                type: 'POST',
                url: $("#form").attr('action'),
                contentType: "application/x-www-form-urlencoded",
                data: {
                    dates : dates_value,
                },

            }); 


        });
</script>  

Note the "onclick" event in the button tag. 注意按钮标记中的“ onclick”事件。 The server side code is working well. 服务器端代码运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM