gpt4 book ai didi

php - AJAX 发布值在 PHP 中被接收为空

转载 作者:可可西里 更新时间:2023-11-01 00:13:16 25 4
gpt4 key购买 nike

我正在尝试将值发布到另一个页面并执行一些 mysql 操作,但这些值作为空对象发布。这是 index.php 文件的脚本部分:

$(document).ready(function() {
$("#picker").datepick();
$('#picker').datepick('setDate', 'today');

$('#submit').click(function() {
var name = $("#name").val();
event.preventDefault();

$.ajax({
type: "POST",
url: "new_prob_submit.php",
data: {
'date': $('#picker').val(),
'name': $('#name').val()
},
success: function() {
alert("success");
}
});
});
});

这是处理我发布的值的 PHP 页面,new_prob_submit.php:

$rep_date = $_POST['date'];
$date = date("yyyy-mm-dd",strtotime($rep_date));
$name = $_POST['name'];
$sql = mysql_query("SELECT * FROM infra.prob_report WHERE prob_rept_name = '$name'");
$rows = array();
while($row = mysql_fetch_array($sql)) {
$nestedData=array();
$nestedData[] = $row["rep_id"];
$nestedData[] = $row["prob_rept_date"];
$nestedData[] = $row["prob_equip_name"];
$nestedData[] = $row["prob_rept_name"];
$nestedData[] = $row["prob_desc"];
$data[] = $nestedData;
}
echo json_encode($data);

最佳答案

问题是你没有用过

dataType:"json" 在你的 ajax 中。

 $.ajax({
type: "POST",
url: "new_prob_submit.php",
//added type
dataType:"json",
data: {
'date': $('#picker').val(),
'name': $('#name').val()
},
success: function() {
alert("success");
}
});

请查看Ajax

关于php - AJAX 发布值在 PHP 中被接收为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34716555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com