2016-07-25 70 views
3

我使用的悬浮窗文件上传,当我返回成功从控制器/错误,我怎么证明它在我的视图文件..展会上悬浮窗文件成功/错误信息上传

查看文件

<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> 

工作甚至没有警告...任何帮助是非常appreciated..Thanks

+0

这是否显示您的控制台中的任何错误? –

+0

是它在控制台响应选项卡上显示“错误”字符串。在控制台中显示“400错误请求”,因为我返回了400错误请求错误。 – Aamir

+0

加入;在'alert('hi');' – paranoid

回答

1

你应该听的事件,并引发无论是成功与否

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

注:您可以建议其他断点here

+0

是uploadWidget的id或者形式的名字? – Aamir

+0

这取决于启动它。你也可以像'var uploader = new Dropzone('#upload-widget',options);'如果你试图拥有 –

+0

这个形式的'id',它现在可以工作了......非常感谢。 – Aamir