如果出现拖放区错误,如何发出警报?



这是我的控制器,我返回错误

if(!empty($chckDocsDup)){
$return['error'] = 1;
return response()->json($return);
exit();
}

在我的 Dropzone 中,我使用this.on('error', function())收到这些错误,但它未能发出警报。有什么其他想法吗?

$(document).ready(function () {
var uplodURLother = '{{url(ADMIN."/uploaddocument")}}';
var metaTokenOther = $('meta[name="_token"]').attr('content');
var uploaddoctypeOther = $('#uploaddoctype_other').val();
Dropzone.options.myDropOther = {
acceptedFiles: ".pdf,.doc,.docx",
url: uplodURLother,
sending: function(file, xhr, formData) {
formData.append("_token", metaTokenOther);
formData.append("doctype", uploaddoctypeOther);
formData.append("candidateid", '{{$candidateDet['candidateid'] }}');
},
init: function() {
this.on("removedfile", function(file) {
$(".remv_"+file.doctype+"_"+file.filecnt).remove();
});
this.on('success', function(file, response) {
alert('hai');
});   
this.on('error', function(file, response) {
alert('response'); //This alert is not working
});
}
};
});

Dropzone 通过查看响应的状态代码来检查上传是否失败。

当你这样做时

return response()->json([]);

默认情况下,Laravel将返回200状态代码。

为了返回错误状态,您需要执行以下操作

return new JsonResponse([], 400);

您可以将400更改为任何4xx状态代码 (IE 422(