【发布时间】:2021-07-10 08:50:43
【问题描述】:
我在 Laravel 中使用 Ajax,每当调用 Ajax 时,输入字段值(为空字符串)都会转换为空值。但我想要空字符串作为回应。我怎样才能得到这个? 我知道我可以映射这些值并将空值转换/设置为空字符串,但效率不高。
我的 Ajax 代码:
$('#settingsForm').on('submit',(e) => {
e.preventDefault();
$.LoadingOverlay("show");
const id = $('#id').val();
const data = new FormData($('#settingsForm')[0]);
$.ajax({
type:'POST',
url: "{{url('company/settings')}}"+'/'+id,
processData: false,
contentType: false,
data: data,
beforeSend: ()=>{
console.log(data);
},
success: (resp) => {
if(resp.code == 200){
toastr.success(resp.type,resp.msg);
}else
toastr.error(resp.type,resp.msg);
$.LoadingOverlay("hide");
}
});
$('#tableRow').show();
$('#settingsDiv').hide();
})
【问题讨论】: