JSON.parse SyntaxError:意外令牌?在JSON中的位置124

时间:2019-03-18 12:23:49

标签: jquery html json ajax

我正在尝试使用$ .ajax()动态地重新加载元素的选项列表。响应正文包含两个字段:下拉HTML和选项数,如下所示: enter image description here

然后我只需将HTML插入元素:

success: function (response) {
                    $("#cmbComplianceUser").html(response.data);
}

当选项列表不包含任何特殊字符时,它可以正常工作。但是,例如,

<option value='845'>Amanda_~!@#$%^&*&#40;&#41;_+{}[]|?/:; Kildee_~!@#$%^&*&#40;&#41;_+{}[]|?/:;</option>

我收到以下错误:

enter image description here

我应该怎么做才能正确解析html内容而没有任何错误,为什么它不解析“?”?符号?

1 个答案:

答案 0 :(得分:0)

我自己想出了一种。我试图使用JSON格式,而没有将输出字符串正确解析为JSON。在服务器上添加了toJSON()解析函数:

Response.ContentType = "application/json"
Response.Write  "{ ""data"": " & toJSON(dropdownHtml) & ", ""total"": " & userCount & " }"