【发布时间】:2019-05-03 12:11:54
【问题描述】:
我的问题是我可以点击按钮,但需要刷新才能删除它。有什么东西让我的 ajax 代码出现问题,为什么它会让人耳目一新?我想要一个按钮,点击删除它会自动删除而不刷新。
我的按钮
<button type="button" data-client_id="{{ $client->id }}" class="btn-archive btn btn-info">Active</button>
<button type="button" data-client_id="{{ $client->id }}" class="btn-delete fa fa-trash btn btn-danger"></button>
我的AJAX
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(document).on('click','.btn-archive',function(){
var clientID=$(this).attr('data-client_id');
var url='/admin/clients/archTrash/'+clientID;
callAjax(url);
});
$(document).on('click','.btn-delete',function(){
var clientID=$(this).attr('data-client_id');
var url='/admin/clients/archTrashPermanent/'+clientID;
callAjax(url);
});
function callAjax(url){
$.ajax({
url:url,
dataType:'json',
type:'GET',
success:function(response){
console.log(response);
},
error:function(err){
console.log(err);
}
});
}
</script>
表结构
` 类客户端扩展模型 { 使用软删除;
protected $dates = ['deleted_at'];
// Table Name
protected $table = 'clients';
// Primary Key
public $primaryKey = 'id';
// Timestamps
public $timestamps = true;`
【问题讨论】:
-
您是删除一行还是只删除数据?你的问题不是很清楚。
-
@Daniel 嗨先生,我正在删除每一行是我很抱歉的误解。
-
您能帮帮我吗?我被困在这里:(@Daniel
-
提供你的表结构。
-
我已经添加了我的模型请看
标签: php html ajax laravel eloquent