What should I return in response to show error message on delete event for blueimp/jquery.file-upload-ui

↘锁芯ラ 提交于 2019-12-24 03:24:31

问题


I am using jQuery File Upload jQuery UI Plugin 8.7.2 from https://github.com/blueimp/jQuery-File-Upload Uploading and deleting of files work successfully. But what should I return in response JSON to show error when deleting of file not finished correctly on server side. For example user have not access for this.

This is my PHP code:

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

回答1:


Heres how I do it in Laravel. You should change the loop to deal with all files received in the 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



回答2:


The UI plugin doesn't seem to do anything with the response so you'd need to modify the jquery.fileupload-ui.js code in order to do something with an error response.



来源:https://stackoverflow.com/questions/29826573/what-should-i-return-in-response-to-show-error-message-on-delete-event-for-bluei

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!