0
在下面的代码中,我正确地从数据库中获取了所有数据。但接下来我想删除特定的数据通过使用删除链接,这是生成动态beloow ..但我不能得到特定的ID发送到delete.php页面上。我总是得到未定义的ID这是我在alert.please中检查它帮助我如何获得ID在myId变量发送到下一页。如何通过使用jquery和ajax动态生成的表中获取id?
<script>
$(document).ready(function(){
var myId=$(this).data('Id');
alert(myId);
$(".delete").click(function(){
$.ajax({
type:"Post",
url:"delete.php",
data:{
Id:myId,
},
sucess:function(data){
}
});
});
});
</script>
<?php
$localhost="localhost";
$username="root";
$password="dheeraj";
$dbname="mydatabase";
$con = mysqli_connect('localhost','root','dheeraj','mydatabase');
if(!$con){
echo mysqli_error($con);
}
$action=$_POST['action'];
if($action=='showComment'){
$sql="select * from employee order by Id";
$result=mysqli_query($con,$sql);
if(mysqli_num_rows($result)>0){
echo "<table border=1px solid red><tr><th>Id</th><th>FirstName</th><th>LastName</th><th>Email</th><th>Contact Number<th>Delete</th></th></tr>";
while($row=mysqli_fetch_array($result)){
echo '<tr><td>'.$row["Id"].'</td><td>'.$row["Fname"].'</td><td>'.$row["Lname"].'</td><td>'.$row["email"].'</td><td>'.$row["contact"].'</td><td><a class="delete" href="?id="'.$row["Id"].'>Delete</a></td></tr>';
}
echo "</table>";
}
}
?>
谢谢先生。其工作正常.. – dheeraj
不客气的队友! –