您确定要删除吗?

时间:2018-07-02 10:50:46

标签: javascript php html laravel

在删除功能上,我没有任何反应时,会显示一条确认删除的消息

控制器功能

public function destroy($id)
{

    $client =client::find($id);
    $client->delete();
    return redirect('client');
}

查看客户

<form action="{{url ('client/'.$client->id)}}" method="post">
                            {{csrf_field()}}
                            {{method_field('DELETE')}}
                            <a href="{{url('client/'.$client->id.'/show')}}" 
 class="btn btn-default btn-sm">Details</a>
                            <a href="{{url('client/'.$client->id.'/edit')}}" 
 class="btn btn-primary btn-sm">Editer</a>
                              <a class="btn btn-danger btn-sm" title="Delete"
                           href="javascript:if(confirm('Are you sure want to 
 delete?')) $('#frm_{{$client->id}}').submit()">
                            Supprimer
                        </a>
                        </form>

Image

3 个答案:

答案 0 :(得分:0)

$('#frm_{{$client->id}}').submit()是jQuery代码,您确定页面正确加载了jQuery吗?

最好使用普通的javascript:document.getElementById("myForm").submit()

答案 1 :(得分:0)

您的路由文件中的内容只需更改

Route::get('/client/{id}/delete', 'ClientController@destroy');

您认为

<a href="{{url ('client/'.$client->id.'/delete')}}" onclick="return confirm('Are you sure?')">Delete</a>

答案 2 :(得分:0)

我认为您忘记为表单添加id属性

<form action="{{url ('client/'.$client->id)}}" id="frm_{{$client->id}}" method="DELETE">