Laravel 5.2 中使用 `return redirect ('xxxx')` 重定向出现 url 地址不变,莫名 Ajax 替换页面内容的问题?

问题已经解决

问题出在jQuery mobile
参照: http://blog.csdn.net/coolcoffee168/article...

Laravel 5.2 中使用 return redirect ('xxxx') 重定向出现url地址不变,莫名ajax替换页面内容的问题

问题的产生和表现

  1. get('login') 获得登录页面。 此时 url: http://aaa.app/login
  2. 填写登录信息,提交。提交后要经过一个中间件,这个中间件中我使用了 return redirect('notice')
    return redirect('notice') 目标的路由是 Route::get('/notice', 'NoticeController@getNotice');getNotice 方法会返回一个视图。
    redirect 执行之后,问题出现了:
    url地址没有变,仍然是 http://aaa.app/login
    但是页面内容却是 Route::get('/notice', 'NoticeController@getNotice'); 对应的视图内容。
    在chrome浏览器中发现,这个页面的内容是 ajax 请求 Route::get('/notice', 'NoticeController@getNotice'); 获得的。
    更不能接受的是,ajax 请求 回的页面内容,其中js代码,form表单丢失了。
    在浏览器中直接访问 http://aaa.app/notice , get的页面是完好的,js代码,form表单都存在。

对应视图代码
ps : 我不能在视图代码中发现明显的结构错误

@extends('layouts.main')
@section('content')
        <div data-role="page" class="signup">
            <div data-role="header" class="jqm-header">
                @foreach($notices as $k => $notice)
                    <h1 class="jqm-logo" style="@if($k != 0) display:none; @endif">{{$notice['title']}}</h1>
                @endforeach
            </div><!-- /header -->
            <div class="agreement-box">
                @foreach($notices as $k => $notice)
                    <div class="agreement-cnt" style="@if($k != 0) display:none; @endif">
                        {!! $notice['content'] !!}
                    </div>
                @endforeach

                <div class="form-btn">
                    <a href="javascript:void(0);"  data-item="0" onclick="noticeNext(this)">确认</a>
                </div>

            </div>
        </div>

    /** 问题描述中的表单 **/    
    <form id="notice">
        @foreach($notices as $notice)
            <input type="hidden" name="notice_id[]" value="{{$notice['id']}}">
            <input type="hidden" name="b_id[]" value="{{$notice['brand_id']}}">
        @endforeach
            {!! csrf_field() !!}
    </form>

    /** 问题描述中的js代码 **/  
    <script type="text/javascript">
        $(function(){
            //........................
            }
        });
    </script>

@endsection

我的疑问是

  1. redirect之后,url地址问什么没有随之改变?
  2. 为什么会产生ajax请求?
  3. 为什么ajax获取的视图内容缺失了js代码,和 form表单?

我也尝试阅读框架源码,可是力有不逮
哪位大大有相似的经历,恳请指点

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 4
leo

这个页面的内容是 ajax 请求 你需要在中间件中判断是不是 ajax 请求,如果是则需要返回 json 格式,然后需要前端配合进行跳转

6年前 评论

@leo 谢谢你的回答。
我没有用ajax去请求问题中的视图,是redirect()执行后自己产生的(我在chrome调试工具中发现这是ajax)。我对redirect()的源码不能通读,不能确定中间哪一步导致产生了ajax。

6年前 评论
leo

@自由飞翔 你的代码看起来就是 ajax 提交,因为你的 form 没有 action 属性

6年前 评论

@leo 这个form是用ajax提交的,但是这个页面本身是redirect()产生的ajax获取的。我的本意是用redirect重定向到这个页面。
现在情况是,页面内容莫名其妙被ajax获取到了。但是js,form表单丢了。

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!