我正在尝试使用ajax更新我的记录,我不知道我在使用我的ajax做错了代码:
(文档)$。就绪(函数(){
$('.edit_tag_button').click(function(){
var id = $(this).parent().find('.tag_id').val();
var formData = {
'tag_type' : $('#tag_type').val(),
'quantity' : $('#quantity').val(),
'number' : $('#number').val(),
'active' : $('#active').val(),
'issued' : $('#issued').val(),
};
$.ajax({
url: "{{url('')}}/update/tagslist/"+id,// Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: formData, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
success: function(data) {
swal("Success!", "Great Job!! Your data has been updated","success");
location.reload();
},
error: function () {
swal("Error", "Look like We got some problem. Can you please refresh the page and try again" , "error");
}
});
});
});
我的控制器代码是:
公共功能updateTags(Request $ request,$ id)
{
$plan = Tags::where('id',$id);
$plan->update($request->all());
}
它表示您的值已成功更新,但它会更新我的值任何帮助plz
答案 0 :(得分:0)
在Laravel POST方法中需要CSRF保护。
确保使用csrf令牌内容添加meta
<meta name="_token" content="{{ csrf_token() }}">
并将其分享给ajax设置。
$.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')}});