点击事件的jQuery脚本问题

时间:2017-03-10 06:25:30

标签: javascript php jquery html ajax

由于某些原因,我的代码似乎根本没有运行jQuery,我花了很多时间试图找出错误并分别测试了我的删除PHP文件

jQuery脚本:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
$.ajaxSetup({ cache: false });
$(document).ready(function(){
    $('#button').on('click', '#btn',function()) {
        var clickBtnName = $(this).attr('name');
        var ajaxurl = 'http://127.0.0.1/SQLDeleteHandler.php';
        var data = {'id': clickBtnName};
        $.post(ajaxurl, data, function(response) {
            window.location.href="http://localhost/store.php";
        });
    });
});
</script>

腓:

$query = "SELECT * FROM accounts";

$resultset= mysqli_query($connection,$query);

while($row = mysqli_fetch_array($resultset,MYSQLI_NUM)){
    echo $row[0]." ".$row[1]." ".$row[2]." ".'<input type="submit" class="btn" name="".$row[0]."" value="delete" />';
    echo "</br>";
}

1 个答案:

答案 0 :(得分:0)

使用它:

&#13;
&#13;
$(document).ready(function(){
    $('.btn').click(function(e){
        e.preventDefault();
        alert('Button is pressed');
        var clickBtnName = $(this).attr('name');
        var ajaxurl = 'http://127.0.0.1/SQLDeleteHandler.php';
        var data = {'id': clickBtnName};
        $.post(ajaxurl, data, function(response) {
            window.location.href="http://localhost/store.php";
        });
    });
});
&#13;
&#13;
&#13;