我应该返回什么来响应blueimp / jquery.file-upload-ui的删除事件上的show error消息

我正在使用jQuery文件上传jQuery UI插件8.7.2来自https://github.com/blueimp/jQuery-File-Upload上传和删除文件工作成功。 但是,如果在服务器端删除未正确完成的文件时,我应该返回JSON以显示错误。 例如,用户无权访问此内容。

这是我的PHP代码:

$response = json_encode( (object) [ 'files' => [ $file->filename => true, ] ] ); return $response; 

这是我在Laravel的表现。 您应该更改循环以处理POST中收到的所有文件

  $json = array( 'files' => array() ); foreach( $request->files as $file ){ $filename = $file->getClientOriginalName().".".$file->getClientOriginalExtension(); $json['files'][] = array( 'name' => $filename, 'size' => $file->getSize(), 'type' => $file->getMimeType(), 'error' => "Your error message" ); } // Return error return response($json); //Laravel: the array get converted to json. You could call json_encode and pass it to your response 

UI插件似乎对响应没有任何作用,因此您需要修改jquery.fileupload-ui.js代码以便对错误响应执行某些操作。