Php 使用“删除”按钮显示员工表
我想知道为什么我下面的代码块在浏览器中没有显示任何内容(http://localhost/display.php). 我想为我的表生成一个模板,以显示数据库中的所有员工(id、firstname、lastname),并在单击显示表上的DELETE按钮时,通过jquery ajax方法使用HTTP动词DELETE删除用户 这是我的display.phpPhp 使用“删除”按钮显示员工表,php,jquery,mysql,html,Php,Jquery,Mysql,Html,我想知道为什么我下面的代码块在浏览器中没有显示任何内容(http://localhost/display.php). 我想为我的表生成一个模板,以显示数据库中的所有员工(id、firstname、lastname),并在单击显示表上的DELETE按钮时,通过jquery ajax方法使用HTTP动词DELETE删除用户 这是我的display.php <table id="employees" border="1"> </table> <script src="h
<table id="employees" border="1">
</table>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$document.ready(function()
{
var $employees = $("#employees");
$.ajax({
url: "delete.php",
contentType: "json",
success: function(data){
$.each(data, function(index, item){
var $row = $("#templates").find(".row-template").clone();
$row.find(".firstName").html(item.FirstName);
$row.find(".lastName").html(item.LastName);
$row.find(".delete").click(function() {
$.ajax({
url: "delaction.php" + item.Id,
type: "DELETE",
success: function()
{
$row.remove();
}
});
});
$employees.append($row);
});
}
});
});
</script>
<div id="templates" style="display: none">
<table>
<tr class="row-template">
<td class="firstName" style="width: 100px;"></td>
<td class="lastName" style="width: 100px;"></td>
<td>
<input type="button" value="X" class="delete" />
</td>
</tr>
</table>
</div>
$document.ready(函数()
{
var$雇员=$(“#雇员”);
$.ajax({
url:“delete.php”,
contentType:“json”,
成功:函数(数据){
$。每个(数据、功能(索引、项目){
var$row=$(“#模板”).find(“.row模板”).clone();
$row.find(“.firstName”).html(item.firstName);
$row.find(“.lastName”).html(item.lastName);
$row.find(“.delete”)。单击(函数(){
$.ajax({
url:“delaction.php”+item.Id,
键入:“删除”,
成功:函数()
{
$row.remove();
}
});
});
$employees.append($row);
});
}
});
});
我的delete.php如下所示
<?php
define('DB_HOST','localhost');
define('DB_ROOT','root');
define('DB_PASS','');
define('DB_NAME','employees');
$conn=mysqli_connect(DB_HOST,DB_ROOT,DB_PASS) or die("Unable to connect to your selected db.Error ".mysqli_error());
if(null!=$conn)
{
mysqli_select_db($conn,DB_NAME);
$query=("SELECT * FROM empl");
$result=mysqli_query($query);
foreach($result as $res)
{
}
mysqli_close($conn);
}
?>
非常感谢。delaction.php中有什么内容 无论如何,要将itemId与要删除的项一起传递给delaction.php,请更改:
url: "delaction.php" + item.Id,
致:
谢谢,但是为什么my display.php什么也不显示?它什么也不显示,因为您对AJAX请求的响应不包含任何数据。阅读
mysqli
用法(mysqli\u fetch\u assoc
)和json\u encode
。
url: "delaction.php?itemId=" + item.Id,