php - 如果出现 Dropzone 错误,如何发出警报?
问题描述
这是我的控制器,我返回错误
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)
推荐阅读
- java - 暂停后,如果加密文件很大(例如 10Gb),恢复下载文件在 IE 中不起作用,它在 Chrome 中工作正常
- java - DBPedia 实时端点给出 504 或 503 异常
- spring-boot - 春季安全实施后,它会阻止我的静态文件夹中的所有资源吗?
- node.js - 如何在监视模式下运行 grunt 文件并启用实时重新加载?
- c# - 自定义打印的保存文件对话框
- xamarin.forms - Xamarin 表单 - 可以部署到 iPhone 但不能部署到 iPad(错误代码 0xe8008015)
- reactjs - 在代码更改时自动创建 webpack 构建 reactjs
- jquery - 使用 Jquery 更改 Bootstrap Collapse 上的图标
- javascript - asp子菜单项的垂直切换
- c# - 如何修复“组合框选定索引始终显示第一个值 C#”