使用ajax

时间:2015-06-01 13:30:22

标签: php ajax

我有一个页面显示用户输入的下拉列表。

选择用户类型后,会显示此用户的表格,每行都有一个复选框。

当我检查其中一个用户并点击删除burron时,用户将从表中删除。

以下是我的HTML页面的主要代码:

<head>
<script>            
    function pop(str){
       var xmlhttp = new XMLHttpRequest();
       xmlhttp.onreadystatechange = function(){
          if(xmlhttp.readyState === 4 && xmlhttp.status === 200 ){                           
              document.getElementById("ajax").innerHTML=xmlhttp.responseText;
          }
       }
       xmlhttp.open("GET","PendingUsersRequestsRefreshForm.php?q="+str,true);
       xmlhttp.send();
    }
</script>
</head>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
    <h2 align = "center">User Type:</h2>
    <select name="type" onchange="pop(this.value)">
    <option value="" >Select User Type</option>
    <?php
        $userType = $_POST['type'];
        foreach($userTypeList as $value){
            DrawSelectListElement($value,$userType); // a function that prints the user types ($userType is the default value to be shown at the dropdown list)
        }
        unset($value);
    ?>
    </select>
    <div id="ajax"> </div>
    <br><br><input name="delete" type="submit" value="Delete Selected"> <br>            
</form>

这是PendingUsersRequestsRefreshForm.php:

<?php
$conn = connectToDB();
$q = $_REQUEST["q"];

if(strcasecmp($q, 'Student') == 0) { 
    echo "<br><h2>Pending Students Requests:<br></h2>";
    $sql = "SELECT uID AS 'User ID', CONCAT('Name: ',FirstName,' ', LastName,'<br>Phone: ',phoneNum,'<br>Mail:',email) AS 'User Details', faculty AS Faculty FROM users_requests WHERE userType = 'Student'";
    $result = mysqli_query($conn,$sql);
    printResultTableWithCheckbox($result,array(0)); // a function that prints the students table    
}

if(strcasecmp($q, 'Academic Advisor') == 0 ) {
    echo "<br><h2>Pending Advisor Requests:<br></h2>";
    $sql = "SELECT uID AS 'User ID', CONCAT('Name: ',FirstName,' ', engLastName,'<br>Phone: ',phoneNum,'<br>',email) AS 'User Details', faculty AS Faculty FROM users_requests WHERE userType = 'Academic Advisor'";
    $result = mysqli_query($conn,$sql);
    printResultTableWithCheckbox($result,array(0));
}

?>

在我选择一些用户并点击删除后,我想看到更新的表格,但我看到的页面只有选择标签而没有更新的表格。

有人可以帮我弄清楚如何在这样的行动之后看到更新的表格

谢谢!

0 个答案:

没有答案