Json代码无法正常工作

时间:2017-04-29 09:36:12

标签: javascript json

错误:

enter image description here

我正在尝试删除邮件记录但是有错误,它不会删除记录。这段代码中的错误请告诉我。

消息查看:

<ul>
<ul class="list-group">
    @foreach($messages as $message)
            <li class="list-group-item"> {{$message->user->name}} : {{$message->message}}
                @if($message->user_id === Auth::user()->id){
                    <a data-id="{{$message->id}}" class="delete-message">Delete</a> /
                    <a href="/message/edit/{{$message->id}}">Edit </a>
                }@endif
            </li>
    </ul>

JSON:

$(".delete-message").on('click', function(e){
e.preventDefault();
var id = $(this).attr('data-id'),
    _this = $(this);
console.log(id);

var _confirm = confirm("Are you sure you want to delete this message?");

if(_confirm){
    $.ajax({
        type : 'DELETE',
        url : '/delete/message/',
        data : {
            id : id,
            _token : $("meta[name=token]").attr('content')
        },
        success : function(res){
            if(res.deleted){
                $(_this).parents('list-group-item').slideUp(function(){
                    $(this).remove();
                });
            }
        }
    });
}else{
    console.log("Never mind!");
}

});

0 个答案:

没有答案