dongpao1921 2016-07-16 15:25
浏览 312
已采纳

SyntaxError:JSON.parse:JSON第1行第2列的意外字符

I need to append this div to another div , but it give me this error :

SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

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)
        }
    }
})
  • 写回答

3条回答 默认 最新

  • dongren9739 2016-07-16 15:27
    关注

    Try this:

    change var respons = jQuery.parseJSON(response); to var respons = response;

    Explanation:

    If the configuration is dataType: json, you'll get a javascript object is no longer necessary JSON.parse

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 C语言PE文件遍历节表
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题
  • ¥15 Selenium+docker Chrome不能运行
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到
  • ¥15 请教一下,openwrt如何让同一usb储存设备拔插后设备符号不变?
  • ¥50 使用quartz框架进行分布式任务定时调度,启动了两个实例,但是只有一个实例参与调度,另外一个实例没有参与调度,不知道是为什么?请各位帮助看一下原因!!
  • ¥50 怎么获取Ace Editor中的python代码后怎么调用Skulpt执行代码