SyntaxError:JSON.parse:JSON第1行第2列的意外字符 [英] SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON
本文介绍了SyntaxError:JSON.parse:JSON第1行第2列的意外字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将此div附加到另一个div,但它会给我这个错误:
I need to append this div to another div , but it give me this error :
SyntaxError:JSON.parse:意外字符在第1行第2列
的JSON数据
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
这是我的javascript代码:
This is my javascript code:
var str = {'message': message,'text': text};
$.ajax({
type: "POST",
url: "api/reply",
data: str,
dataType: "json",
cache: false,
success: function(response)
{
var respons = jQuery.parseJSON(response);
var type = respons.status
if (type == 'success') {
$("<div></div>").html(respons.message).appendTo("#messages");
}
else
{
toastr.error(respons.message)
}
}
})
推荐答案
试试这个:
更改 var respons = jQuery.parseJSON(response);
to var respons = response;
说明:
如果配置是dataType:json,你将不再需要javascript对象JSON.parse
If the configuration is dataType: json, you'll get a javascript object is no longer necessary JSON.parse
这篇关于SyntaxError:JSON.parse:JSON第1行第2列的意外字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文