douhuanqiao5290 2015-10-27 12:42
浏览 118
已采纳

Laravel 5.1 - 关于Ajax导航的刷新页面

In my app i have configured my navigation with ajax, so i can get my view's content (so only pure HTML) very quickly. I've also implemented javascript's history, so i can modify url on navigation.

But when i refresh the page on a url like my-app-/news, of course i get the same content asked by ajax: the view with only html, but in this case i need a complete view, not only the content.

route.php

Route::get('/', 'PagesController@index');
Route::get('/{page}', 'PagesController@ajaxCall');

PagesController.php

class PagesController extends Controller {

    public function index(){
        return view('pages.index');
    }

    public function ajaxCall($page){
        return view('content.'.$page)->render();
    }

}

How to create another route and method like my index where i can call the full view on page refresh?

  • 写回答

2条回答 默认 最新

  • douxiawei9318 2015-10-27 13:04
    关注

    You can detect if the request was made via AJAX:

    class PagesController extends Controller {
    
        public function index(){
            return view('pages.index');
        }
    
        public function ajaxCall($page){
    
            if(\Request::ajax()) {
               return view('content.'.$page)->render();
            } else {
               return ... //complete view
            }
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序