[英]PHP can't get ajax data sent
我正在使用jquery多個日期選擇器,當我將用戶選擇的日期發送到另一個.php頁面時,出現錯誤:未定義的索引:日期。 這是我的代碼:
<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>
和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,
},
});
});
最后,來自target.php文件的php
$dates = $_POST['dates'];
if (isset($dates)) {
echo "OK";
}
和日歷:
$(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"
}); });
錯誤在target.php頁面上。
有人可以幫助我嗎? 非常感謝你
這是完整的代碼:
<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>
和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>
注意按鈕標記中的“ onclick”事件。 服務器端代碼運行良好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.