在 dropzone 文件上传时显示 success/error 消息

Show success/error message on dropzone file upload

我正在使用 dropzone 文件上传,当我 return 来自控制器的成功/错误时,我如何在我的视图文件中显示它..

查看文件 ,

 <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">&times;</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>

甚至警报都不起作用...非常感谢任何帮助...谢谢

监听事件,成功与否触发

Dropzone.options.uploadWidget = {
  init: function() {
    this.on('success', function( file, resp ){
       alert("Success");
    });
  },
  ...
};

注意:您可以按照建议设置其他断点here