public function index()
{
if (request()->ajax()) {
// Here I have a long query.....
return request()->page ? $query->paginate(15) : $query->get();
}
return view('ads.ads');
}
So when the request is ajax I return json, otherwise I return a view. But when I want to visit the previous page I see a white page with only json, instead of the view!
I also had this once, I solved it by always apending ?json or &json to all of my ajax requests with the use of an interceptor so it is done automatically. This prevents the browser returning you the wrong cached page when you click 'back'.
But I suppose there is a more elegant solution to the problem. But this was a quick fix that worked for me and I never looked for another solution.
@Lars-Janssen I've used it in a project with vue-resource (an ajax helper for vue which is abandoned now). I don't know what you are using but the axios library also has intercepters so the idea would be the same I guess.
Vue.http.interceptors.push(function (request, next) {
// prepend request url with a parameter to prevent caching issues
let glue = request.url.indexOf('?') === -1 ? '?' : '&';
request.url = request.url + glue + 'json';
});