You need to give your sessionlists unique ids aswell.(您还需要为会话列表提供唯一的ID。)
Because when you append your myhtmlstring to #sessionlist it only ever takes the first one.(因为当您将myhtmlstring附加到#sessionlist时,它只会占用第一个。)
<ul id="sessionlist<?php echo $module->id; ?>" class="list-group list-group-flush">
<li class="list-group-item">
<i class="icon-play_circle_outline text-blue"></i><a href="#">'+data[i].session_name+'</a>' +
</li>
</ul>
then you can append it to the right sessionlist in your ajax success:(然后可以将其添加到ajax成功的正确会话列表中:)
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
const currentModuleId = this.id
$.ajax({
url: "<?php echo base_url(); ?>dashboard/displaysession/" + currentModuleId ,
type: 'GET',
data: {},
error: function () {
alert('Something is wrong');
},
success: function (data) {
for (var i = 0; i < data.length; i++) {
var myhtmlstring = '<li class="list-group-item">' +
'<i class="icon-play_circle_outline text-blue"></i><a href="#">' +
data[i].session_name + '</a>' +
'</li>';
console.log($.parseHTML(myhtmlstring));
$("#sessionlist" + currentModuleId ).append($.parseHTML(myhtmlstring));
}
},
dataType: 'json'
});
});
});
</script>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…