我有以下脚本:
<script>
$(document).ready(function(){
setInterval(function() {
$.ajax({
type: "GET",
url: "<?php echo base_url(); ?>profile/load_data",
dataType: "JSON",
success: function(people) {
waiting_list=$('#waiting_list').empty();
$.each(people, function(i, waiting){
waiting_list.append('<a href="profile/details">'+waiting.id+" "+waiting.lname+" "+waiting.sname+'</a>');
});
},
error: function(data) {
// alert('An error occured, kindly try later');
}
});
}, 10000);
});
</script>
我想通过在链接末尾添加一个变量(id)来创建动态网址,使其成为href =“profile / details / id。我该怎么做?
答案 0 :(得分:3)
在waiting.id
中附加href
,例如 href =“个人资料/详细信息/'+ waiting.id +'”
<强>代码,强>
success: function(people) {
waiting_list=$('#waiting_list').empty();
$.each(people, function(i, waiting){
id=waiting.id;
lname=waiting.lname;
sname=waiting.sname;
waiting_list.append('<a href="profile/details/'+id+'">'+id+" "+lname+" "+sname+'</a>');
// Append id here ---------------^---------
});
},
答案 1 :(得分:1)
尝试
waiting_list.append('<a href="profile/details/'+waiting.id+'">'+waiting.id+" "+waiting.lname+" "+waiting.sname+'</a>');
});