gpt4 book ai didi

javascript - jQuery ajax使用成功事件,如何获取json属性

转载 作者:行者123 更新时间:2023-11-28 08:58:43 28 4
gpt4 key购买 nike

使用 success 事件执行 jquery ajax 请求:

     $.ajax("/subscribe/email", {
type: 'POST',
dataType: 'json',
data: {
email: $("#e").val()
},
success: function(result) {
console.log(result.err);
}
});

问题是 result.err 未定义,但响应是 json 并且具有此属性。

{
"err": "Some error message goes here."
}

如何通过 result 访问 javascript 对象的属性。

最佳答案

听起来你需要解析 json。现代浏览器可以做到:

JSON.parse(result).err

或者使用 jQuery:

$.parseJSON(result).err

关于javascript - jQuery ajax使用成功事件,如何获取json属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18070431/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com