当关闭UploadCare对话框时,我希望显示警报,但事实并非如此。为什么不呢?''
$('#uc_open').on('click', function() {
uploadcare.openDialog(null, {
imagesOnly: true
}).done(function(file) {
file.done(function(fileInfo) {
//
}).fail(function(error, fileInfo) {
alert(error);
});
});
return false;
});
答案 0 :(得分:3)
您已订阅openDialog().done()
。当用户选择文件并在对话框中单击“完成”时,将调用此回调。在此回调中,您会收到file
个对象并订阅file.fail()
回调。当文件上传因网络错误或验证器不满意而失败时,将调用此回调。
如果您想在用户关闭对话框时订阅回调而不选择文件(通过单击右上角的×或按ESC键),您应该订阅openDialog().fail()
:
$('#uc_open').on('click', function() {
// Open the dialog on button cick
uploadcare.openDialog(null, {
imagesOnly: true
}).done(function(file) {
// User has just clicked "Done" in Uploadcare dialog
file.done(function(fileInfo) {
// File uploading succeeded
});
}).fail(function(error, fileInfo) {
// User just has closed the dialog by pressing ESC or clicking on "×"
alert(error);
});
return false;
});