[英]Laravel cant get data from ajax request
I am trying to save data in DB but all validations return error while data exist.我正在尝试将数据保存在数据库中,但所有验证在数据存在时都返回错误。
Here is data that I sent to backend(controller) but in dd()
it returns []
这是我发送到后端(控制器)的数据,但在
dd()
它返回[]
My JS我的JS
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('.customerUpdate').on('click', function(e){
e.preventDefault();
var ordID = $(this).data('id');
var formData = new FormData();
formData.append('group_id', $('#group_id').val());
formData.append('industry_id', $('#industry_id').val());
formData.append('customername', $('#customername').val());
formData.append('companyName', $('#companyName').val());
// Attach file
formData.append('npwp', $('input[type=file]')[0].files[0]);
formData.append('province_id', $('#province_id').val());
formData.append('city_id', $('#city_id').val());
formData.append('address', $('#address').val());
formData.append('postalCode', $('#postalCode').val());
formData.append('email', $('#email').val());
formData.append('phone', $('#phone').val());
formData.append('user1Project', $('#user1Project').val());
formData.append('user1MobilePhone', $('#user1MobilePhone').val());
formData.append('user2Project', $('#user2Project').val());
formData.append('user2MobilePhone', $('#user2MobilePhone').val());
formData.append('userFinancePayment', $('#userFinancePayment').val());
formData.append('userFinancePaymentMobilePhone', $('#userFinancePaymentMobilePhone').val());
formData.append('userFinanceTax', $('#userFinanceTax').val());
formData.append('userFinanceTaxMobilePhone', $('#userFinanceTaxMobilePhone').val());
formData.append('userProcurement', $('#userProcurement').val());
formData.append('userProcurementMobilePhone', $('#userProcurementMobilePhone').val());
$.ajax({
type:'PUT',
url:'{{url('dashboard/customers')}}/'+ordID,
data: formData,
async: false,
cache: false,
contentType: false,
dataType: 'JSON',
enctype: 'multipart/form-data',
processData: false,
success:function(data){
alert(data.success);
}
});
});
});
Any idea?任何的想法?
Try using @method('PUT')
or add formData.append('_method', 'PUT');
尝试使用
@method('PUT')
或添加formData.append('_method', 'PUT');
in your form and change your request type to type:'POST'
, because some browser doesn't support PUT request, let Laravel decide the request with the _method
request在您的表单中并将您的请求类型更改为
type:'POST'
,因为某些浏览器不支持 PUT 请求,让 Laravel 使用_method
请求来决定请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.