I'm working on a project i need a load more button i tried the following code but i think something is wrong.
there is a load more button on click see all some more results should display. on click see all it calls the controller method but i think i am not able to post data to controller method what wil i get from ajax response.
here following is my code which i tried.
View
<div class="form-group border-bottom pb-3">
<label for="usr" class="f-14 bold black">Manufacturers</label>
<div class="pl-md-4 pl-2">
<label class=" my-checkbox gry2">Show All Manufacturers
<input type="checkbox">
<span class="checkmark"></span>
</label>
@if(count($leedManufacturers) > 0 )
@foreach($leedManufacturers as $leedsManufacturer)
<label class=" my-checkbox gry2" id="manufacturer">
<input type="checkbox">
<span class="checkmark"></span>
</label>
"> --}}
@endforeach
@endif
<a class="load-more" id="load" href="#" class="f-14 bold">See All</a>
<input type="hidden" id="row" value="0">
<input type="hidden" id="all" value="">
</div>
</div>
Script
<script type="text/javascript">
$(document).ready(function(){
// Load more data
$('.load-more').click(function(){
var row = Number($('#row').val());
var allcount = Number($('#all').val());
var rowperpage = 3;
row = row + rowperpage;
if(row <= allcount){
$("#row").val(row);
$.ajax({
url: "",
type: 'post',
data: {row:row},
success: function(data){
alert(data);
}
});
}else{
console.log('if is not working');
}
});
});
</script>
Controller:
public function colabrativetwo(Request $request, $slug = 0, $division_id = 0, $section_id = 0, $manufacturer_id = 0, $list=""){
$row = $request->row;
$manufacturersFeatured = Product::select('manufacturers.id AS id', 'manufacturers.name AS name', DB::raw('COUNT(DISTINCT products.id) as products_count'))
->whereIn('products.status', ['active'])
->where(function ($query) {
$query->where('products.low_emitting_material_prerequisite_file', '!=', '');
})
->where('users.user_type', 'manufacturer_paid')
->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')
->leftJoin('sections', 'products.section_id', '=', 'sections.id')
->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')
->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')
->join('users', 'manufacturers.user_id', '=', 'users.id')
->orderBy('name', 'asc')
->groupBy('manufacturers.id')
->limit($row)
->get();
return view('guest::new_design_frontend.product-library', $manufacturersFeatured);}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire