I try to run the script for every @foreach loop like in the code below. But it seems the script only work only for the first loop. How to make it run for every loop ?
@foreach ($list as $e)
@section('js')
<script type="text/javascript">
function a(){
$.ajax({
url: '{{ url("get-topik/") }}/{{ $e->id }}'
})
.done(function(data) {
var html="";
for(var i=0;i<data.length;i++){
html += '<span class="badge badge-pill badge-sm badge-primary" style="background-color: #51b3f9">'+data[i].get_topik.topik+'</span>'
}
$("#topik").append(html)
});
}
a();
</script>
@endsection
<span id="topik">
</span>
@endforeach
Thanks Before :)