Ajax post请求将发送的数据附加到返回的JSON中
Ajax post request is appending sent data to the returned JSON
我有一个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);
}
});
它被发送到并用this处理:
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 ?
相关文章:
- Jquery:对返回JSON数据的php脚本的Ajax调用
- 返回JSON中的下标
- jQuery Map 从多个源返回 JSON 对象
- 如何在 Node.js 中返回 JSON 后停止代码流
- AngularJS:表单提交没有返回JSON中的值
- 使用ajax发送数据,返回json
- 从我的解析函数返回json
- 如何从脚本页面返回json数据
- 有些人有任何关于如何使用Modified Java Script Value处理返回Json(url)的示例
- 如何在html页面中从ajax返回json数据
- Ajax调用在本地返回json,但在服务器上运行时返回xml
- ajax调用返回JSON ParseError即使认为JSON看起来是正确的
- 调用.ajax方法得到未定义的json结果,返回json格式列表<字符串>
- 如何通过C#返回JSON并用JavaScript进行解析
- 使用 AJAX 返回 json 数组
- 从 AJAX 命令返回 JSON 格式的响应
- 如何通过node中的请求返回JSON.js(从javascript)
- Node.js API 在终端中返回 JSON,但不在浏览器中返回 JSON
- 如何在支柱 2 中返回 JSON 数组
- Rhino:从 Java 中返回 JSON