2014-09-29 99 views
0

我得到了我的問題,當會話過期我不會移動到登錄頁面,但我得到的錯誤是無法連接到塞雷爾語作爲我的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的網址文件作爲

<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到登錄頁面幫助我如何o在任何調用ajax代碼之前檢查會話。

感謝和問候

回答

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(); ?> 
相關問題