gpt4 book ai didi

javascript - 在 Jquery ajax 的 onclick 函数中传递数据

转载 作者:行者123 更新时间:2023-11-30 09:44:43 24 4
gpt4 key购买 nike

我在 Jquery ajax 中遇到问题...

我想在函数中传递一个值,这是我的代码:

$.each(data, function (index, value) {
id = value['req_id'];
notification.onclick = function () {
alert(id);return false;

$.ajax({
url : "<?php echo base_url(); ?>dashboard/notificationUpdated",
type : 'post',
data : {'id':id},
dataType: "json",
success : function(data){}
});
};
});

当 id 被提醒时,它显示“未定义”。如何解决这个问题,我想将这个值传递给 Controller ​​....谁能帮我这个???等待回应............

数据=>

{  
"0":{
"req_id":"368"
},
"1":{
"req_id":"371"
},
"2":{
"req_id":"372"
},
"3":{
"req_id":"373"
},
"4":{
"req_id":"375"
},
"5":{
"req_id":"376"
},
"6":{
"req_id":"378"
},
"7":{
"req_id":"379"
},
"8":{
"req_id":"380"
},
"9":{
"req_id":"382"
},
"10":{
"req_id":"385"
},
"11":{
"req_id":"386"
},
"12":{
"req_id":"387"
},
"13":{
"req_id":"399"
},
"14":{
"req_id":"400"
},
"15":{
"req_id":"404"
},
"16":{
"req_id":"405"
},
"17":{
"req_id":"406"
},
"18":{
"req_id":"418"
},
"19":{
"req_id":"419"
},
"20":{
"req_id":"422"
},
"21":{
"req_id":"424"
},
"22":{
"req_id":"425"
},
"23":{
"req_id":"428"
},
"24":{
"req_id":"429"
},
"25":{
"req_id":"430"
},
"26":{
"req_id":"431"
},
"27":{
"req_id":"432"
},
"28":{
"req_id":"434"
},
"status":"success"
}

最佳答案

试试这个:

$.each(data, function (index, value) {
var id = value['req_id'];
notification.onclick = function () {
alert(id);

$.ajax({
url : "<?php echo base_url(); ?>dashboard/notificationUpdated",
type : 'post',
data : { id: id },
dataType: "json",
success : function(data){}
});

};
});

关于javascript - 在 Jquery ajax 的 onclick 函数中传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39361992/

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