【发布时间】:2015-02-15 07:22:32
【问题描述】:
我有两个页面使用相同的 js 文件来调用某个 PHP 文件并从那里以 JSON 格式获取数据。虽然进入 PHP 文件的数据与输出的数据完全相同,但 Ajax 在第二页返回 'parsererror' SyntaxError: JSON.parse: unexpected character at line 1 column 1 JSON 数据。
$.ajax({
type: 'POST',
dataType: "json",
data: {objtyp: this.objtyp, objid: this.objid},
url: '/admin/getfieldsadd.php',
success: function(data) {
//not going to happen
},
error: function (xhr, status, text) {
switch (status) {
case 404:
alert('File not found');
break;
case 500:
alert('Server error');
break;
case 0:
alert('Request aborted');
break;
default:
alert('Unknown error: ' + status + " " + text);
}
}
那么有人遇到过同样的问题吗?
【问题讨论】:
-
查看开发者工具中的响应。确保响应中除了 JSON 之外没有任何内容。
-
@Barmar, here
-
@void,之前的评论。
标签: javascript php ajax json