我在会话过期后遇到问题我没有移动到登录页面但是因为无法连接到serer而出现错误,因为我的ajax代码看起来像
function driver()
{
$this = $(this);
$.ajax(
{
url: 'view/driver/driver.php',
datatype: 'html',
async:true,
success: function(data){
$box = $('#content');
$box.after(data);
$box.remove();
}
});
}
$(document).on('click','#driver',$(this),driver);
和php url文件
<div id="content" class="span10">
<!-- content starts -->
<div class="row-fluid sortable">
<div class="box span12">
$userid=$_SESSION['USERID'];
if(empty($userid)){
header('location:localhost/test/login.php');
}
<div class="box-header well" data-original-title>
<h2><i class="icon-user"></i> All Driver</h2>
</div>
<div class="box-content">
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Driver user ID</th>
<th>FName</th>
<th>LName</th>
<th>Phone NO.</th>
<th>Is Verified</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include '../../config.php';
$query = "select * from driver_user";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
?>
<tr>
<td style="width: 8%;"><?php echo $row['driver_user_id']; ?></td>
<td style="width: 10%;"><?php echo $row['first_name']; ?></td>
<td style="width: 10%;"><?php echo stripslashes($row['last_name']); ?></td>
<td style="width: 8%;"><?php echo $row['phone_no']; ?></td>
<td style="width: 5%;<?php if($row['isverified'] == 'Verified'){ echo 'color:green;';}
if($row['isverified'] == 'Approval'){ echo 'color:blue;';}
if($row['isverified'] == 'Not Verified'){ echo 'color:red;';}
?>"> <?php echo $row['isverified']; ?></td>
<td style="width:15%;" class="center" itemid="<?php echo $row['driver_user_id']; ?>">
<a class="btn btn-success driver_view" href="#">
<i class="icon-zoom-in icon-white driver_view"></i>
View/ Edit
</a>
<!-- <a class="btn btn-info driver_edit_form" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>-->
<a class="btn btn-danger delete_driver" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
<?php } ?>
</tr>
</tbody>
</table>
</div>
</div><!--/span-->
</div><!--/row-->
<div class="row-fluid sortable">
</div><!--/row-->
<!-- content ends -->
</div><!--/#content.span10-->
如果会话过期我没有移动到登录页面但它显示错误无法连接到php文件中的数据库首先我检查会话
plz帮助我在调用ajax代码之前检查会话。
感谢和问候
答案 0 :(得分:0)
您无法使用标题在向浏览器发送数据后,您已开始向浏览器发送数据:
<div id="content" class="span10">
要么使用location.href javascript或
而不是标题缓冲
<? ob_start();?>
<div id="content" class="span10">
.....
if(empty($userid))
{
header('location:localhost/test/login.php');
exit;
}
......
<? ob_flush(); ?>