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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?