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.
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
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.
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
For the view
For the json data