以下是功能,
list.PHP的
<script type="text/javascript">
function massDelete()
{
if (!confirm("Are you sure"))
{
return false;
}
else
{
var selecedids = $("#selectedids").val();
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("success").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "ajax_delete.PHP?massDelete=" + selectedids.value, true);
xhttp.send();
}
}
return false;
}
</script>
ajax_delete.PHP
<?PHP
if (!empty($_REQUEST['massDelete'])) {
$selectId = $_REQUEST['massDelete'];
$finalId = ltrim($selectId, ",");
$sql = MysqL_query("delete from contact_form where contactUser_id in ($finalId)", $con);
if ($sql) {
// echo '<script>';
//echo 'var parent = document.getElementById("fullTable")';
//echo 'element.remove(parent)';
//echo '</script>';
echo "sucess deleted";
} else {
echo "Please select a Contact to delete";
}
}
?>
响应确实给了我成功的消息,但在某个地方我想要消除下面的HTML表作为响应
list.PHP的
<?PHP
echo '<table id="fullTable">';
echo "<tr><td> ";
echo '<input type="checkBox" name="checkAll" id="checkAll"/></td>';
echo '<td colspan="8" align="right">';
echo '<button type="submit" onClick="return massDelete()" name="delete" class="deleteall" id="deleted">Delete All</button></td>';
echo "</tr>
<tr>
<th></th>
<th>FirsT NAME</th>
<th>LAST NAME</th>
<th>EMAIL</th>
<th>PHONE</th>
<th>FAX</th>
<th></th>
<th></th>
<th></th>
</tr>";
while ($row = MysqL_fetch_array($results)) {
echo '<div id="checkBoxlist">';
echo '<tr class="show">';
echo '<td><input name="checkBox[]" type="checkBox" class="checkBox1" value="' . $row['contactUser_id'] . '" id="CheckBox1"></td>';
echo '<td>' . $row['first_name'] . '</td>';
echo '<td>' . $row['last_name'] . '</td>';
echo '<td>' . $row['email'] . '</td>';
echo '<td>' . $row['phone'] . '</th>';
echo '<td>' . $row['fax'] . '</td>';
echo '<td><a href="addedit.PHP?id=' . $row['contactUser_id'] . '">Edit</a></td>';
echo '<td><a class="delete" href="#" id="' . $row['contactUser_id'] . '">Delete</a></td>';
echo '<td><a href="view.PHP?id=' . $row['contactUser_id'] . '" target="_blank">View</a></td>';
echo '</div>';
}
} else {
echo '<td colspan="9"><h1>No contacts found.</td></h1>';
}
?>
我很困惑我应该怎么做,如果删除一行而不是只有那一行消失,
但是如果选中所有复选框进行删除,而不是成功,那么整个表格应该会消失.
解决方法:
所以听起来像PHP成功删除它,因为当你刷新页面时,正确的数据显示出来.
但是,如果必须刷新页面以使其正确显示,则需要确保返回正确的信息并正确解析.只需console.log()响应xhttp.responseText,看看是否返回了正确的数据,然后仔细检查你是否正确解析它(适当地更改dom).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。