dtwbp26022
2019-05-21 14:34
浏览 57
已采纳

虽然我在控制台中看到了新页面,但是laravel jquery ajax没有重定向

I want to do this in laravel: https://laravel.com/docs/5.6/redirects

I have a simple button, a named route, and I want the route to redirect to another page.

Although I see the new page in the network console of Chrome, the page itself is not actually redirecting.

(I don't want to use the window.location.href in the javascript function as I want the route to do the job.)

layout.blade.php

    $("#myRedirectButton").click(function(){

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
            method: 'post',
            dataType: 'text',
            url: 'redirect-testing-link',
            success: function (data)
            {

            }
        });

    });

routes/web.php

Route::post('/redirect-testing-link', function () {
    return redirect()->route('gidis');
});


Route::get('/gosterge_paneli', function () {
    return view('gosterge_paneli');
})->name('gidis');
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douxian5076 2019-05-21 14:49
    最佳回答

    You can't do a serverside redirect after an AJAX request, so what you ask is very hard.

    The simplest ways to solve it are by using either the window.location you wanted to avoid, or skip the whole AJAX call and use an <a> element.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题