【发布时间】:2020-02-02 09:33:37
【问题描述】:
在 JSON.stringify ,我的 javascript 在控制台中给出以下消息。
parsererrorSyntaxError: JSON 输入意外结束
var contentData = {
"Location": {
"City": "Bangalore Urban",
"State": "Karnataka",
"Country": "IN"
},
"Packages": [
"3 days and 4 nights"
],
"Hotels": "Vividus",
"Offers": [
"Enjoy up to 20% Savings",
"Hotel Discounts, Just for Booking Early.2 nights B&B to include first night dinner"
],
"Activities": [
"scuba diving",
"swimming"
]
}
$.ajax({
type : 'POST',
url : '/my/reco/pkg.',
data : JSON.stringify(contentData),
async : false, // I get this message both with false and true here.
contentType : "application/json; charset=utf-8",
success : function(data) {
console.log(data);
},
error : function(jqXHR, textStatus, message) {
console.log("error"+jqXHR+textStatus+message);
}
});
当我在 chrome 中打开调试器时,我在 JSON.stringify 处看到错误。
我已经验证了 json 和 javascript 代码,两者在语法上似乎都是正确的。
我可以在 chrome 的 header 部分下的网络选项卡中找到请求 json。
我在这里做错了什么或错过了什么?
【问题讨论】:
-
contentData 是什么样的?服务器是否还会返回实际的 JSON 或 404 页面?
-
请关闭服务器并再次运行它可能会有所帮助。
-
为什么不将它作为 JSON 发送并添加 dataType: 'json' ?
-
如果服务器端有模型,则无需对数据进行字符串化
-
@ElyasEsna 但请求甚至没有到达服务器端。
标签: javascript jquery ajax aem aem-6