【问题标题】:Laravel Ajax route issue (404 response)Laravel Ajax 路由问题(404 响应)
【发布时间】:2016-08-27 01:08:48
【问题描述】:

当我使用 ajax 请求时,我遇到了 Laravel 5 中返回 404 的路由问题。 本地一切正常,但是当我通过 git 在 laravel forge 服务器上上传它时,它返回 404,就好像路由文件没有上传一样。 所以我得到了一个 SFTP 并检查了,文件确实被上传了。

控制器:

public function getNewAjaxPosts(){
    $post = DB::table('posts')->orderBy('created_at', 'desc')->paginate(16);
    return view('/pages.ajax-loaded-view', array('post' => $post))->render();
}

public function getNewAjaxTrending($page){
    $return = DB::select( DB::raw("SELECT *, count(views.video_id) as visningar FROM posts,views WHERE posts.id = views.video_id AND 
          posts.created_at >= DATE_ADD(LAST_DAY(DATE_SUB(NOW(), INTERVAL 2 MONTH)), INTERVAL 1 DAY) 
          GROUP BY posts.id order by visningar DESC LIMIT 15 OFFSET :page"),["page" => $page]);

    return View::make('/pages.ajax-load-trending', array('trending' => $return))->render();
}

路线:

Route::get('/ajax/posts', "VideoController@getNewAjaxPosts");

Route::get('/ajax/trending/page/{page}',"VideoController@getNewAjaxTrending");

Javascript 文件:

function getNewPosts(page) {
    $.ajax({
        url: '/ajax/posts?page=' + page
    }).done(function(data) {
        if (data != "") {



            $('.ajax-container').append(data);


        } else {
            $(window).unbind("scroll");
            $(".ajax-container").append("<div class='endofstream'> <i class='fa fa-paper-plane' aria-hidden='true'></i> Du har tittat igenom allt! Vad kul. glöm inte att kolla in oss på facebook </div>")
        }
    });
}

function getNewPostsTrend(page) {
    $.ajax({
        url: '/ajax/trending/page/' + page * 15 + "/"
    }).done(function(data) {



        $('.ajax-trending').append(data);


    });
} // This is just a sample script. Paste your real code (javascript or HTML) here.

if ('this_is' == /an_example/) {
    of_beautifier();
} else {
    var a = b ? (c % d) : e[f];
}

如果您想查看实时示例:

http://www.sportmossa.se

一旦您向下滚动到页脚(ish),该事件就会触发,并且控制台将记录错误。

【问题讨论】:

    标签: php ajax laravel routes


    【解决方案1】:

    我找到了答案。

    我的路线被缓存了,duuh...所以答案是工匠路线:缓存

    希望有一天这可能对其他人有所帮助。

    保重!

    【讨论】:

      猜你喜欢
      • 2014-10-11
      • 2017-11-27
      • 2015-06-11
      • 1970-01-01
      • 2015-02-24
      • 2020-08-27
      • 2020-11-10
      • 2014-08-14
      • 2018-11-20
      相关资源
      最近更新 更多