2016-09-18 56 views
0

我想根據選擇篩選將顯示給用戶的結果,但是,它沒有正確顯示,我不知道我做錯了什麼。我在同一頁面上使用GET進行處理(users.php?rid =)。這是我選擇一個值時顯示的方式。看來它加載網頁的兩倍到DIV無法正確使用jquery.load()功能

enter image description here

選擇按鈕

<select name="role_id" id="role_id" style="width: 150px;" 
     onchange=""> 
    <option value="">Select User</option> 
    <?php 
    $rid = 0; 
    if (isset($_GET['rid'])) { 
     $rid = clean($_GET['rid']); 
    } 
    $roles = get_user_roles(); 
    foreach ($roles as $row): 
     ?> 
     <option 
      value="<?php echo $row['role_id']; ?>"<?php if (isset($rid) && $rid == $row['role_id']) echo 'selected'; ?>> 
      <?php echo $row['name']; ?> 
     </option> 
    <?php endforeach; ?> 
</select> 

結果DIV

<div id="filter_result"> 

    <table class="table table-striped" > 
     <thead> 
     <tr> 
      <th><div>#</div></th> 
      <th><div>Name</div></th> 
      <th><div>Email</div></th> 
      <th><div>User Type</div></th> 
      <th><div>Options</div></th> 
     </tr> 
     </thead> 
     <tbody> 
     <?php 
     if ($rid < 1) { 
      $users = get_users(); 
     } else { 
      $users = get_role_users($rid); 
     } 
     if ($users->num_rows < 1) { 
      echo '<div class = "alert alert-warning text-center">There are no Students for this Class.... <a class="btn btn-primary btn-sm" href="add_user.php">Add User</a></div>'; 
     } 
     $count = 1; 
     foreach ($users as $row):?> 
      <tr> 
       <td><?php echo $count++; ?></td> 
       <td><?php echo $row['name']; ?></td> 
       <td><?php echo $row['email']; ?></td> 
       <td><?php echo get_role_name($row['role_id']); ?></td> 
       <!--Options--> 
       <td> 
        <!--Change Role--> 
        <div class="btn-group"> 
         <button type="button" class="btn btn-primary btn-sm dropdown-toggle" 
           data-toggle="dropdown"> 
          Change Role <span class="caret"></span> 
         </button> 
         <ul class="dropdown-menu dropdown-default pull-right" role="menu"> 
          <?php $roles = get_user_roles(); 
          foreach ($roles as $row2): 
           ?> 
           <li> 
            <a href="change_roles.php?rid=<?php echo $row2['role_id'].'&uid='.$row['user_id'];?>"> 
             <?php echo $row2['name']; ?> 
            </a> 
           </li> 
          <?php endforeach; ?> 
         </ul> 
        </div> 
        <!--Delete Student--> 
        <a href="delete_user.php?id=<?php echo $row['user_id']; ?>" 
         onclick="confirm('Are You sure?')" class="btn btn-danger"> Delete</a> 
       </td> 
      </tr> 
     <?php endforeach; ?> 
     </tbody> 
    </table> 
</div 

JAVASCRIPT

<script> 
    $(document).on('change', 'select#role_id', function() { 
     var role_id = $(this).val(); 
     $('#filter_result').load('users.php?rid='+role_id, '#filter_result'); 

    }); 
</script> 

它應該顯示像在同一個頁面上此 enter image description here

+0

希望你是通過控制檯debbuging F12 – JOUM

回答

1

既然你檢查的選擇,你可以指定ID,你的身體標記,例如

<body id="page_body"> 

然後用#page_body.load(),它將工作

$('#page_body').load('users.php?rid='+role_id, '#filter_result'); 
+0

它工作感謝 – Mysterio4