Reputation: 143
I am developing a website in Laravel 5, It has a Jobs page where data loaded through ajax which have many filters. When I open a link and come back to the previous page (Jobs page) by clicking the browser back button, it showing me Json data on the browser window instead of loading the whole page.
Kindly let me know how to solve this issue.
Upvotes: 0
Views: 217
Reputation: 35200
If you're using the same url for the JSON request as you are for the html request then the browser will simply be returning the last response to that url which will be the JSON data.
There are a few different ways to overcome this but essentially you'll have to modify your url so that the browser treats them as different responses.
One way would be to append a query string value to the ajax call e.g. ?json
.
A slightly more complex yet more flexible approach would be to create separate controllers for your views and JSON data and then prefix your JSON routes with something like /api
e.g.
For the view
example.com/jobs -> Pages/JobsController@index
For the json data
example.com/api/jobs -> Api/JobsController@index
Upvotes: 2