【发布时间】:2016-11-28 17:48:17
【问题描述】:
我正在使用 dropzone 文件上传,当我从控制器返回成功/错误时,如何在我的视图文件中显示它..
查看文件,
<div class="box-body">
@if ( $errors->count() > 0 )
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ $message = 'Please select csv file only.' }}
</div>
@endif
{!! Form::open([ 'url' => 'admin/reports','class' => 'dropzone', 'id' => 'reportfile' ]) !!}
{!! csrf_field() !!}
<div class="col-md-12">
<h3 style="text-align : center">Select File</h3>
</div>
<button type="submit" class="btn btn-primary">Upload Report</button>
{!! Form::close() !!}
</div>
控制器代码
if ($request->hasFile('file')) {
$file = Input::file('file');
$validator = Validator::make(
[
'file' => $file,
'extension' => strtolower($file->getClientOriginalExtension()),
], [
'file' => 'required',
'extension' => 'required|in:csv',
]
);
if ($validator->fails()) {
return Response::json('error', 400);
}
JS 代码
<script>
window.onload = function () {
Dropzone.options.reportfile = {
paramName: "file",
maxFilesize: 2,
error: function (file, response) {
alert('hiii')
},
init: function () {
this.on("addedfile", function (file) {
alert("Added file.");
});
},
accept: function (file, done) {
alert('hi')
if (file.name == "justinbieber.jpg") {
done("Naha, you don't.");
}
}
};
};
</script>
甚至警报都不起作用......非常感谢任何帮助......谢谢
【问题讨论】:
-
这是否在您的控制台中显示任何错误?
-
是的,它在控制台响应选项卡上显示“错误”字符串。当我返回 400 错误请求错误时,还在控制台中显示“400 错误请求”。
-
添加;在
alert('hi');
标签: javascript php laravel laravel-5.1 dropzone.js