Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单ajax函数发送空id_Php_Ajax - Fatal编程技术网

Php 简单ajax函数发送空id

Php 简单ajax函数发送空id,php,ajax,Php,Ajax,我正在尝试使用简单的deleteajax函数。我并不擅长ad JS,但当我点击按钮delete时,我可以在Chrome开发控制台中看到id=NULL,当我刷新页面时,条目又回来了。ajax函数非常简单 $("body").on("click",".remove-item",function(){ var entry_id = $(this).parent("td").data('entry_id'); var c_obj = $(this).parents("tr");

我正在尝试使用简单的deleteajax函数。我并不擅长ad JS,但当我点击按钮delete时,我可以在Chrome开发控制台中看到id=NULL,当我刷新页面时,条目又回来了。ajax函数非常简单

$("body").on("click",".remove-item",function(){
    var entry_id = $(this).parent("td").data('entry_id');
    var c_obj = $(this).parents("tr");

    $.ajax({
        dataType: 'json',
        type:'POST',
        url: 'delete.php',
        data:{entry_id:entry_id}
    }).done(function(data){
        c_obj.remove();
        toastr.success('Item Deleted Successfully.', 'Success Alert', {timeOut: 5000});

    });
});
还有按钮

<button  class="btn btn-danger remove-item" > Delete</button>
你知道会出什么问题吗

更新。桌子

    echo '<table class="table">
        <thead>
            <tr>
                <th>#</th>
                <th>Name</th>
                <th>Transaction Quote</th>
                <th>Action</th>
            </tr>
        </thead>';
        foreach($pdo->query("SELECT * FROM entries ORDER BY entry_id DESC LIMIT 20") as $row){                                                          
            echo '
                <tbody>
                <tr>
                    <td>'.$row['entry_id'].'</td>
                    <td>'.$row['entry_name'].'</td>
                    <td>'.$row['entry_transaction_quote'].'</td>
                    <td><button  class="btn btn-sm btn-danger remove-item" ><i class="glyphicon glyphicon-trash"></i> Delete</button></td>
                </tr>
                </tbody>  ';
        }
        echo '  </table>
用类名更改您的td

试试这个

Html应该是

<tr entry_id="<?=$row['entry_id']?>">
   <td><button  class="btn btn-sm btn-danger remove-item" ><i class="glyphicon glyphicon-trash"></i> Delete</button></td>
</tr>
var entry_id = $(this).parent().parent().attr("entry_id");

您可能应该在'data:{entry\u id:entry\u id},data:{entry\u id:entry\u id}'中加上一些引号`您可以在这里显示html表以检索id吗;显示id??先检查一下?然后只保留数据:输入id和php$\u POST['data'];并从AjaxTD中删除数据类型。td元素没有dataset属性,我认为var entry_id=$this.parenttd.data'entry_id';正在查找,不是吗?您没有任何数据属性,所以var entry_id=$this.parenttd.data'entry_id';==很高兴帮助你:是的,我已经做了标记。就等了15分钟。再次感谢。
var entry_id = $(this).parent("td").parent("tr").find('.entry_id').text().trim();
<tr entry_id="<?=$row['entry_id']?>">
   <td><button  class="btn btn-sm btn-danger remove-item" ><i class="glyphicon glyphicon-trash"></i> Delete</button></td>
</tr>
var entry_id = $(this).parent().parent().attr("entry_id");