This question already has an answer here:
这个问题已经有了答案:
- What is causing “Uncaught SyntaxError: Unexpected token o” with $.parseJSON() and JSON.parse() [duplicate] 4 answers
- 什么导致了“未捕获的SyntaxError:意外的令牌o”和$.parseJSON()和JSON.parse()[重复]4个答案?
I have a web app I am working on:
我有一个我正在做的网页应用:
$("#post").click(function () {
var u = $('#u').val();
var j = $('#j').val();
$.post("http://www.myweb.php", {
u: u,
j: j
})
.done(function (data) {
var obj = jQuery.parseJSON(data);
alert(obj.status );
//alert("Data Loaded: " + data);
});
});
When it tries to retrieve the JSON I get:
当它试图检索JSON时:
Uncaught SyntaxError: Unexpected token o
1 个解决方案
#1
8
You don't have to call .parseJSON()
. Your response has already been parsed. You're getting that error because the object you pass to jQuery.parseJSON()
is being converted to the string "[object Object]"
. The unexpected token is that "o" in "object".
您不必调用. parsejson()。你的反应已经被解析了。您将得到这个错误,因为您传递给jQuery.parseJSON()的对象被转换为字符串“[object object]”。意想不到的标记是“对象”中的“o”。
#1
8
You don't have to call .parseJSON()
. Your response has already been parsed. You're getting that error because the object you pass to jQuery.parseJSON()
is being converted to the string "[object Object]"
. The unexpected token is that "o" in "object".
您不必调用. parsejson()。你的反应已经被解析了。您将得到这个错误,因为您传递给jQuery.parseJSON()的对象被转换为字符串“[object object]”。意想不到的标记是“对象”中的“o”。