我需要在上传过程中实现服务器错误。这是我的代码:
$(document).ready(function () {
$("#@clientId").fineUploader({
request: {
endpoint: '@(Url.Content("~/Admin/Download/AsyncUpload"))'
},
template: "@(clientId)-qq-template",
multiple: false
}).on("complete", function (event, id, name, responseJSON, xhr) {
$("#@(clientId + "downloadurl")").html("<a href='" + responseJSON.downloadUrl + "'>@T("Admin.Download.DownloadUploadedFile")</a>");
$("#@(clientId + "value") input").val(responseJSON.downloadId);
$("#@(clientId + "remove")").show();
});
});
handling errors上的手册我发现没有帮助。
有任何线索吗?
答案 0 :(得分:2)
Fine Uploader服务器可以返回多个response values。要返回服务器错误消息,您只需返回响应success
值false
(这将触发错误回调)并使用您想要的任何消息填充error
值:
{
"success": false,
"error": "bad filesize"
}
然后使用此响应做一些有意义的事情,只需利用onError
回调:
.on("error", function(event, id, name, reason) {
alert(qq.format("Error on file {} (id = {}). Reason: {}", name, id, reason));
})