I can't access javascript from partial view Laravel using AJAX load more paginate. View which created from load more ajax in partial view can't access btn-vote click function.
here's my simple's code :
index.blade.php
@extends('layout')
@section('content')
<div class="list-group" id="result">
@include('dataview')
</div>
@endsection
@section('js')
<script type="text/javascript">
$(document).ready(function() {
function loadmore() {
// doing load more data if end of page/page++
// ajax to load data
// return partial view 'dataview' with data from API
// append to div id="result"
}
$('.btn-vote').off('click').on('click', function(e) {
// button click and do ajax thing
// return data
});
});
@endsection
my dataview.blade.php
@foreach($datas as $data)
<a href="#" class="list-group-item list-group-item-action">
<div style="float: right;">
<button type="button" class="btn btn-sm btn-vote" data-id={{$data->id}}>
Vote | {{$data->count}}
</button>
</div>
</a>
@endforeach
And here's my ajax controller to load more data and create partial dataview
public function load(Request $request) {
$datas = Post::paginate(15);
if ($request->ajax()) {
$view = view('data',compact('datas'))->render();
return response()->json(['html'=>$view]);
}
return view('index', compact('datas'));
}