Laravel前一页内容加载问题 [英] Laravel previous page content loading issue

查看:68
本文介绍了Laravel前一页内容加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Laravel 5中开发一个网站,它有一个Jobs页面,其中通过ajax加载的数据具有很多过滤器.当我打开链接并单击浏览器后退按钮返回上一页(作业页面)时,它将在浏览器窗口中显示Json数据,而不是加载整个页面.

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.

推荐答案

如果您对JSON请求使用的网址与对html请求使用的网址相同,则浏览器将只返回对该网址的最后响应将是JSON数据.

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.

一种方法是将查询字符串值附加到ajax调用中,例如?json.

One way would be to append a query string value to the ajax call e.g. ?json.

一种稍微复杂但更灵活的方法是为视图和JSON数据创建单独的控制器,然后为JSON路由添加诸如/api之类的前缀

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.

查看

example.com/jobs -> Pages/JobsController@index

对于json数据

example.com/api/jobs -> Api/JobsController@index

这篇关于Laravel前一页内容加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆