Amit Kumar
Amit Kumar

Reputation: 143

Laravel previous page content loading issue

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.

enter image description here

Kindly let me know how to solve this issue.

Upvotes: 0

Views: 217

Answers (1)

Rwd
Rwd

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

Related Questions