Laravel 5.2 中使用 `return redirect ('xxxx')` 重定向出现 url 地址不变,莫名 Ajax 替换页面内容的问题?
问题已经解决
问题出在jQuery mobile
参照: http://blog.csdn.net/coolcoffee168/article...
Laravel 5.2 中使用 return redirect ('xxxx')
重定向出现url地址不变,莫名ajax替换页面内容的问题
问题的产生和表现
- get('login') 获得登录页面。 此时 url:
http://aaa.app/login
- 填写登录信息,提交。提交后要经过一个中间件,这个中间件中我使用了
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
我的疑问是
- redirect之后,url地址问什么没有随之改变?
- 为什么会产生ajax请求?
- 为什么ajax获取的视图内容缺失了js代码,和 form表单?
我也尝试阅读框架源码,可是力有不逮
哪位大大有相似的经历,恳请指点
推荐文章: