jQuery将数据发布到div

时间:2016-01-29 20:24:35

标签: php jquery

./gradlew connectedDevelopmentDebugAndroidTest

我正在尝试在DIV #txtHint中显示datepicker发布数据。它工作,但它将整页html发布到这个div。我只希望在<?php if(isset($_POST['date'])) { $date = strtotime($_POST['date']); $day = strtolower(date("D", $date)); } ?> <script> $(function() { $( "#datepicker" ).datepicker($.extend({ constrainInput: true, altField: ".alternate", altFormat: "yy-mm-dd", minDate: 0, firstDay: 1, onSelect:function(dateText,instance) { $.post("index.php", { date:dateText }, function(data) { $('#txtHint').html(''); $('#txtHint').html(data); }); } }, )); }); </script>

中显示帖子信息

这是index.php:

<div id="txtHint"></div>

我特别希望它在一个页面中。没有为帖子数据调用外部脚本。 有人可以建议吗?

1 个答案:

答案 0 :(得分:1)

更改index.php以便在响应AJAX请求后退出,并且不会打印完整的HTML文件。

<?php
$today = strtotime(date("d-m-Y"));
$now = strtotime(date("H:i"));
$before = "-".$settings['close_before']." hours";
if(isset($_POST['date'])) {
    $date = strtotime($_POST['date']);
    $day = strtolower(date("D", $date));
    // THIS HERE SHOULD BE RETURNED TO TXTHINT DIV BELOW IN FORM
    echo "<select name=\"time\" class=\"form-control\" disabled>";
    echo "<option value=\"\">".$day."</option>";
    echo "</select>";

    exit(); // <<=== Add this
}
?>