-1

我在几个网站上搜索了我的问题,但我无法得到它。我正在寻找的是如何在响应返回成功删除行的消息后刷新页面。我的页面 admin2.php 显示来自 DB 的管理员信息以及学生表(来自 DB),该表在学生的每一行旁边都有一个复选框。我通过 Ajax 发送表单(表格)以转到(admin3Response.php)页面进行检查,然后返回响应。这是我的代码有问题。

admin2.php

      <tr><th>Admin Information</th>
        <th style="width: 212px"></th></tr>
      <tr><td><b>Admin Name: <?php echo $name; ?></b><span name="adminName"></span></td>
        <td style="width: 212px"><b>Admin ID: <?php echo $userID; ?></b><span name="adminID"></span></td></tr>
      <tr><td><b>Phone: <?php echo $phone; ?></b><span name="adminPhone"></span></td>
        <td style="width: 212px"><span></span></td></tr>

admin2.php 这是我想要刷新的表单。从此表中,我可以选择要删除的学生。

else if(isset($dropStudent))
{

if(mysql_num_rows($QueryResult7) == 0)
  {
            ?>
    <h2><?php echo ("There are no students available.");?></h2>
    <p>
    <div class="form_settings">
    <input class="submit" type="button" onclick="goBack()" name="delete0" value="Back" style="margin-left: 0px; width: 89px">
    </div>
    <?php
     }
else 
{
?>

<form name="form3" id ="form3" method="" action="admin2.php"  >
<input type="hidden" value="Delete" name="deleteStudent">
<?php
echo $adminUser;
?>
<TABLE style="width:100%; border-spacing:1;">


<TR><TH>Choose</TH><TH>USER_ID</TH><TH>STUDENT NAME</TH><TH>EMAIL</TH><TH>PHONE</TH>                   <TH>MAJOR</TH><TH>GPA</TH><TH>DEGREE</TH></TR>
<?php

$Row7 = mysql_fetch_row($QueryResult7);
// reads row of query into indexed array
// advances result pointer
do
{
echo '<TR><TD><input type="checkbox" name="checkbox[]" value="' . $Row7[0] .  '"></TD>'            .
"<TD>{$Row7[0]}</TD>

<TD>{$Row7[1]}</TD>" .
"<TD>{$Row7[2]}</TD>

<TD>{$Row7[3]}</TD>" .
"<TD>{$Row7[4]}</TD>

<TD>{$Row7[5]}</TD>" .
"<TD>{$Row7[6]}</TD>

</TR>";

$Row7 = mysql_fetch_row($QueryResult7);

} while ($Row7); // tests for content of null

?>

<input type="hidden" value="<?php echo $countStds; ?>" name="countStds">
<input type="hidden" value="<?php echo $adminUser; ?>" name="adminUser">


<tr>
<td colspan="10"> 

</tr>
<?php
mysql_close($DBConnect);
?>
</TABLE>
</form>
<script>
// $("#form3") grabs the above form with an ID of "form3"
$("#form3").on('submit', function(){

    // Grab all form values
    var values = $("#form3").serialize();
    // Send form values over ajax
    $.ajax({
        method: 'POST',
        url: 'admin3Response.php',
        data: values,
        // execute when response comes back from admin3Response.php
        success: function(data){
            // data = whatever admin3Response echo'd back
            // check for success
            if (data.lastIndexOf("success") >= 0) {

                // no errors
                    alert("Student was dropped successfully");

        window.location.reload(true); // It reload an empty page; didn't work
                //alert("TODO: redirect user somewhere?");
            } else {
                // Display error message
                alert(data);
            }
        }
    })
    return false;
});
  </script>          
  <?php

  }
  }

admin3Response.php

else if(isset($deleteStudent))

{

 if (isset($checkbox))
{       

 for($i=0; $i<$countStds; $i++)
{
    $delStudent = $checkbox[$i];
    $wholeStudents = mysql_query("DELETE USERS, ENROLLMENTS, OVERIDES FROM          USERS, ENROLLMENTS, OVERIDES WHERE USERS.USER_ID = ENROLLMENTS.USER_ID AND   ENROLLMENTS.USER_ID = OVERIDES.USER_ID AND USERS.USER_ID = '$delStudent'"); 
    $delUserStudent = mysql_query("DELETE USERS FROM USERS WHERE USER_ID =    '$delStudent'");
    $delOverStudent = mysql_query("DELETE OVERIDES, USERS FROM OVERIDES, USERS  WHERE USERS.USER_ID = OVERIDES.USER_ID AND USERS.USER_ID = '$delStudent'");
    $delEnrStudent = mysql_query("DELETE ENROLLMENTS, USERS FROM ENROLLMENTS,  USERS WHERE USERS.USER_ID = ENROLLMENTS.USER_ID AND USERS.USER_ID = '$delStudent'");     
}

 echo ("You have deleted "); echo count($checkbox);  echo (" student(s)   `enter code here`successfully."); 


echo ("success");
 }
 else
 { 
 echo ("No student selected"); 
 }

 mysql_close($DBConnect);    

 }

我尝试使用“window.location.reload(true);”,但它重新加载了一个空页面。我的猜测是我需要使用 get 方法将所有变量从 admin3Response.php 传递给 admin2.php 但我不知道该怎么做。任何帮助将不胜感激。

4

2 回答 2

0

很多方法,我想你可以这样做:

    window.location.reload();
    history.go(0);
    window.location.href=window.location.href;

如果您想重定向到另一个页面更改

 window.location="Path"
于 2013-08-02T10:12:41.120 回答
0

试过这个?

if (data.lastIndexOf("success") >= 0) {
    // no errors
    alert("Student was dropped successfully");
    window.location = window.location;
}
于 2013-08-02T20:41:35.540 回答