我有这样的ajax代码。我想在重新加载后显示我的flash数据(通过JS)
$.ajax({
type: "GET",
url: "{{ URL::to('admin/deposit/ajaxapprove') }}",
data: mydata,
success : function(result){
//set_flashdata session
location.reload();
}
});
如何设置flashdata会话以在重新加载页面后显示警报?我想在引导程序警报上显示flash数据会话。。
您可以这样使用--
<?php if($this->session->flashdata('success')) { ?>
<script>alert('ok');</script>
<?php } ?>
在代码点火器文件中设置闪光消息
// load session library if not auto-loaded
$this->session->set_flashdata('msg', 'Category added');
当控件返回到Ajax请求时,它将重新加载页面则检查是否设置了闪烁消息
<?php if($this->session->flashdata('msg')){ ?>
//Here goes you bootstrap alert code
<?php } ?>
我遇到了同样的问题,我按照以下方法(javascript方法)进行了快速解决。
<div class="col-md-12 alert-container"></div> <!-- alert container -->
$.ajax({
type: "GET",
url: "{{ URL::to('admin/deposit/ajaxapprove') }}",
data: mydata,
success : function(result){
var alert =`<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data- dismiss="alert" aria-hidden="true">×</button>Success message here </div>`;
$('.alert-container').html(alert); /* alert container class ".alert-container" */
setTimeout(function(){ /* show the alert for 3sec and then reload the page. */
location.reload();
},3000);
}
});
我也有同样的问题。解决方案很简单。在成功函数下,您只需键入:
<?php $this->session->set_flashdata('msg-success',"//your messages here"); ?>