gpt4 book ai didi

javascript - 相同数据的 Ajax 错误(解析器错误 : SyntaxError: JSON. 解析:JSON 数据第 1 行第 1 列出现意外字符)

转载 作者:行者123 更新时间:2023-11-28 07:36:39 25 4
gpt4 key购买 nike

我有两个页面使用相同的 js 文件来调用某些 PHP 文件并从那里获取 JSON 格式的数据。尽管 PHP 文件中获取的数据和获取的数据完全相同,但第二页上的 Ajax 返回“parsererror”SyntaxError: JSON.parse: JSON 数据第 1 行第 1 列出现意外字符。

        $.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);
}
}

有人遇到过同样的问题吗?

最佳答案

这听起来让人想起 dreaded BOM 。摘自该链接:

At the beginning of a page that uses a Unicode character encoding you may find some bytes that represent the Unicode code point U+FEFF BYTE ORDER MARK (abbreviated as BOM).

The BOM, when correctly used, is invisible.

也许检查文件的编码是否设置为UTF8 Without BOM

关于javascript - 相同数据的 Ajax 错误(解析器错误 : SyntaxError: JSON. 解析:JSON 数据第 1 行第 1 列出现意外字符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28523904/

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