Javascript AJAX调用传递<;部门>;而不是<;按钮>;一
我想知道为什么这个ajax调用传递的是div id而不是我想要传递的按钮idJavascript AJAX调用传递<;部门>;而不是<;按钮>;一,javascript,php,jquery,ajax,call,Javascript,Php,Jquery,Ajax,Call,我想知道为什么这个ajax调用传递的是div id而不是我想要传递的按钮id <?php while($info = mysqli_fetch_array($sql)) { echo "<tr> <th>" .$info['name']. "</th> <th>" .$info['pass'].
<?php
while($info = mysqli_fetch_array($sql))
{
echo "<tr>
<th>" .$info['name']. "</th>
<th>" .$info['pass']. "</th>
<th><a href=\"http://" .$info['link']. "\">" .$info['link']. "</a></th>
<th><div class=\"delbuttons\" id='5'> <button data-toggle=\"modal\" data-target=\"#myModal\" id='" .$info['id']. "'> Delete </button> </div> </th> </tr> ";
}
?>
</table>
<script>
$(document).ready(function(){
$('.delbuttons').click(function() {
$.ajax({
type: 'get',
url: 'ajax.php',
data: {
row: this.id
},
success: function(msg){
if (msg)
alert(msg);
location.reload();
}
});
});
});
</script>
您正在选择$('.delbuttons')
,因此此
指的是
或者选择$('.delbuttons button')
,或者使用$(this.children(“:first”).attr(“id”)
而不是this.id
,您选择的是$('.delbuttons')
,因此this
指的是
或者选择$('.delbuttons button')
,或者使用$(this.children(“:first”).attr(“id”)
而不是this.id