gpt4 book ai didi

javascript - 如何使用 jquery 和 ajax 更新 json 中的数据

转载 作者:行者123 更新时间:2023-11-28 06:57:34 24 4
gpt4 key购买 nike

我正在尝试更新我的 json,如果 uid = 0090000219 我想更改我的“ secret ”

我有这个 json:

[
{
"id":23,
"uid":"0090000219",
"cid":"0090000013",
"extension":"201",
"secret":"Myojyo42_f",
"leader":true,
"simultaneous":false,
"confbridge_id":17,
"created_at":"2015-09-02 12:49:12",
"updated_at":"2015-09-02 12:49:12"
},
{
"id":24,
"uid":"0090000221",
"cid":"0090000013",
"extension":"203",
"secret":"Myojyo42_f",
"leader":false,
"simultaneous":false,
"confbridge_id":17,
"created_at":"2015-09-02 12:49:12",
"updated_at":"2015-09-02 12:49:12"
},
{
"id":25,
"uid":"0090000220",
"cid":"0090000013",
"extension":"202",
"secret":"Myojyo42_f",
"leader":false,
"simultaneous":false,
"confbridge_id":17,
"created_at":"2015-09-08 07:40:04",
"updated_at":"2015-09-08 07:40:04"
},
{
"id":26,
"uid":"0090000223",
"cid":"0090000013",
"extension":"205",
"secret":"Myojyo42_f",
"leader":false,
"simultaneous":false,
"confbridge_id":17,
"created_at":"2015-09-08 07:40:04",
"updated_at":"2015-09-08 07:40:04"
}
]

这是我的代码,但它没有更新:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
var conf_url = "https://192.168.236.33/confbridge_participants/conference_participants.json?cid=0090000013";
getParticipant(conf_url, function(data){

for (var i=0; i<data.length; i++) {
if (data[i].uid == 0090000219) {
data[i].secret = "Secret";
break;
}
}

alert("New secret: " + data[2].secret);
});
function getParticipant(conf_uri, handleData) {
$.ajax({
type: "GET",
url: conf_uri,
dataType: "jsonp",
jsonpCallback: 'callback',
contentType: "application/javascript",
success: function(data) {
handleData(data);
// console.log(data);
}
});

}
</script>

最佳答案

您正在查看错误的值来检查它是否成功。您需要检查数组中的第一个对象,而不是第三个......

alert("New secret: " + data[0].secret);

关于javascript - 如何使用 jquery 和 ajax 更新 json 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32452754/

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