我有一个表单,我想通过 ajax-post 发送给我的控制器。同时 HTML 正在等待记录的生成和保存,我想显示进度(现在只是数字)。我真的不明白为什么下面的代码没有<div id="progress">
用Session::get('progress')
.
控制器:
public function postGenerate() {
// getting values from form (like $record_num)
Session::flash('progress', 0);
$i = 1;
for ($i; $i < $record_num; $i++) {
$record = new Record();
// adding attributes...
$record->save;
Session::flash('progress', $i);
}
$response = Response::make();
$response->header('Content-Type', 'application/json');
return $response;
}
Run Code Online (Sandbox Code Playgroud)
Javascript:
@section('scripts')
<script type="text/javascript">
$(document).ready(function() {
$('#form-overview').on('submit', function() {
setInterval(function(){
$('#progress').html( "{{ Session::get('progress') }}" );
}, 1000);
$.post(
$(this).prop('action'),
{"_token": $(this).find('input[name=_token]').val()},
function() {
window.location.href = 'success';
}, …
Run Code Online (Sandbox Code Playgroud)