2016-07-25 71 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