I would like to load the data from the database without reloading the whole page with jquery.
Just like in this pen: https://codepen.io/gabrieleromanato/pen/kheox?q=jQuery%3A%20filterable%20portfolio%20%20&order=popularity&depth=everything&show_forks=false
My Index.blade php:
<div class="row">
<ul class="categories">
@foreach ($category as $category)
<li>
<a href="{{ route('category', $category->id) }}"> <class = "se ni dolocen"> {{ $category->title }} ({{ $category->companies->count() }}) </a>
</li>
@endforeach
</ul>
<div class="companies_list">
@foreach($categories as $companies)
<div class="col_3">
@if ($companies->image_url)
<img src="{{ $companies->image_url }}" class="podjetjaslike" alt="" href="{{ route('companies.showp2ps', $companies->id) }}">
@endif
<div class="tags"> <object>
<a href="/premium" title="Premium" class="premium">Premium</a>
</object><div class="rate color4">{{ $companies->rating }}</div>
</div></a>
<div class="content">
<a onclick="" href="{{ route('companies.showp2ps', $companies->id) }}">
<h3>{{ $companies->title }}</h3></a>
<p>{{ $companies->categorie_id }}.</p>
<div class="bottom">
<div class="time">{{ $companies->date }}</div>
</div>
</div>
</div>
@endforeach
This is my page.controller:
public function category($id) {
$category = Category::with('companies')->orderBy('title', 'asc')->get();
//\DB::enableQueryLog();
$categories = Companies::Paginate()
->where('category_id', $id);
return view("pages.index", compact ('categories', 'category')); //->render();
//dd(\DB::getQueryLog());
}
In the end of index.php. I have jquery script:
<script type="text/javascript">
var Browse = {
sort: function(items) {
items.show();
$('ico_list').find('col_3').not(items).fadeOut(500);
},
showAll: function(items) {
items.fadeIn(500);
},
doSort: function() {
$('li', 'categories').on('click', function() {
var $li = $(this);
if (!$li.is('#all')) {
var items = $({{ $companies->id }});
Browse.sort(items);
} else {
Browse.showAll($('col_3', 'companies_list'));
}
});
}
};
Browse.doSort();
</script>
How should I do to reload the data dynamic with jquery to not reload the page?