我有一个运行POST方法的JavaScript,一旦我的datepicker失去焦点(我也在常规提交按钮上尝试了这个)并运行脚本rent-fetch-pick-up-point.php
。 PHP运行,但它没有超过if语句,因为我没有获得POST数据。 datepicker绑定到输入字段time-period-from
datepickerTo.blur(function(){
if (selectedDateFrom.length > 0) {
datepickerFrom.delay(500).queue(function(){
$.ajax({
type: "POST",
url: "include/rent-fetch-pick-up-point.php",
data: {action: selectedDateFrom},
success: function(data) {
$("#pick-up-point-container").html(data);
}
});
});
}
});
这是PHP代码:
if (isset($_POST['time-period-from'])) {
require '../include/connection.php';
$dateFrom = $_POST['time-period-from'];
$sql = "SELECT * FROM order WHERE $dateFrom BETWEEN date_from AND date_to";
$result = mysqli_query($connection, $sql);
$numRows = mysqli_num_rows($result);
echo $sql; // For testing purposes
}
以下是HTML:
<input type="text" name="time-period-from" id="datepicker-from" class="datepicker"></p>
我也尝试使用$ .post()而不是$ .ajax(),但我遇到了同样的问题:
$.post("include/rent-fetch-pick-up-point.php", {name: selectedDateTo}, function(data) {
$("#pick-up-point-container").text(data)
});
答案 0 :(得分:2)
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(left, right, bottom, top, zNear, zFar);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
的键来自您传递给$_POST
选项的对象的键,而不是最初来源的表单字段的名称。自从您使用:
data:
值将在data: { action: selectedDateFrom }
,而不是$_POST['action']
。所以你需要使用:
$_POST['time-period-from']
和
if (isset($_POST['action']))
或者您可以将Javascript更改为:
$dateFrom = $_POST['action'];
答案 1 :(得分:0)
我认为你的selectedDateFrom变量是一个数组,导致你的帖子信息无法正常使用。
data: {action: $('#selectedDateFrom').serializeArray()}
然后您可以正确获取表单数据
答案 2 :(得分:0)
你并没有在PHP方面抓住正确的变量:
if (isset($_POST['action'])) {
require '../include/connection.php';
$dateFrom = $_POST['action'];
$sql = "SELECT * FROM order WHERE $dateFrom BETWEEN date_from AND date_to";
$result = mysqli_query($connection, $sql);
$numRows = mysqli_num_rows($result);
echo $sql; // For testing purposes
}