gpt4 book ai didi

javascript - Ajax post 请求将发送的数据附加到返回的 JSON

转载 作者:行者123 更新时间:2023-12-03 05:41:30 24 4
gpt4 key购买 nike

我有一个像这样的ajax调用:

$.ajax({
url: '/assets/functions.php',
type: 'POST',
data: {
"functionCall": "get-uploads",
"type": type
},
dataType: 'json',
success: function (data, textStatus) {
console.log("done");
console.log(data);
console.log(textStatus);
},
error: function(textStatus, errorThrown) {
console.log("uh oh");
console.log(textStatus);
console.log(errorThrown);
}
});

它被发送到并处理:

switch($_POST['functionCall']) {
.
.
.
case "get-uploads":

$type = $_POST['type'];
$getUploads = "SELECT * FROM pp_uploads WHERE type = '$type';";

$docArray = array();

while($row = mysql_fetch_assoc($documents)) {
$docArray[] = $row;
}

echo json_encode($docsArray);
}

当我运行这个程序时,我收到一个解析错误,据我所知,这意味着返回的数据不是以 JSON 形式返回的。于是我把dataType改成了html,看到控制台返回的数据是:

[{"id":"35","filename":"fdgsdf","path":"ConfiguratorTreeDiagram.pdf","type":"resources"},{"id":"36","filename":"gsrewg","path":"dhx_advertising.pdf","type":"resources"}]Array
(
[functionCall] => get-uploads
[type] => resources
)

所以看起来我传递到调用中的数据被附加到我的数据的末尾。我该如何防止这种情况发生?

最佳答案

看起来您可能在数组变量的某处执行 print_r 操作?

关于javascript - Ajax post 请求将发送的数据附加到返回的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40514218/

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