gpt4 book ai didi

php - 发送到 $_POST 的 Jquery var 未完成查询,返回错误

转载 作者:行者123 更新时间:2023-11-29 21:38:13 25 4
gpt4 key购买 nike

我今天一直在试图弄清楚我做错了什么,并尝试了各种方法来完成这项工作。基本上,我通过 POST 将一个名为 id 的 var 发送到一个 php 文件,然后该文件运行一个查询并带回数据。 print_r 显示已发送正确的数据(在本例中为单个数字),但查询不是返回名称等,而是无法识别 $_POST['id' ] 并返回错误。

$(document).ready(function() {
$(".side-menu_description").click(function() {
var id = $(this).attr("id");
if ($.trim(id) != "") {
/*
$.post("index_loads/series_load.php", { 'id': id }, function(data) {
alert(data);
$("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");
});
*/

$.ajax({
url: 'index_loads/series_load.php/',
data: { "id": id },
type: 'POST',
success: function(data) {
$("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");
alert(data);
},
error: function(){
alert("Error: Could not return");
}
});
}
});
});
<?php 
print_r($_POST);
//$_POST['id'] = file_get_contents('php://input');

$q = "SELECT * FROM Series WHERE SeriesID = '$_POST[id]'";
$r = mysqli_query($dbc, $q);
$data = mysqli_fetch_assoc($r);
?>

警报的前几行:

Array
(
[id] => 5
)

<h1> </h1>
<!--<h2>

Airs At: <br />
<b>Notice</b>: Undefined offset: 1 in <b>C:\xampp\htdocs\myname\index_loads\series_load.php</b> on line <b>24</b><br />
: </h2>-->

<h3>Rating:<br> Stars + (4.0)</h3>

我尝试了各种方法,从使用 $.ajax 到将数据更改为 { "id="+ id}file_get_contents > 但它们似乎都不起作用。我可能遗漏了一些东西,但搜索后我仍然找不到答案!

提前致谢。

最佳答案

改变

$("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");

$("#wrap").fadeOut("slow").html(data).fadeIn("slow");

关于php - 发送到 $_POST 的 Jquery var 未完成查询,返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34745553/

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