没有调用FineUploader OnComplete [英] FineUploader OnComplete not being called

查看:66
本文介绍了没有调用FineUploader OnComplete的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在onComplete调用上遇到了麻烦.它似乎没有在onComplete内部运行代码.这是我所拥有的:

I'm having trouble with the onComplete call. It does not seem to be running the code inside onComplete. Here is what I have:

<script>
    $(document).ready(function () {
        $("#fine-uploader").fineUploader({
            request: {
                endpoint: 'upload2.php'
            },
            text: {
                uploadButton: 'Upload a file'
            },
            callbacks:{
                onComplete: function(id, fileName, responseJSON) {
                        alert("completed");
                        if (responseJSON.success) {
                            $('#imgPreview').html('Thumbnail:<img src="../images/test/' + fileName + '" alt="' + fileName + '">');
                        }
                   }
            }
        });

    });
</script>

尽管文件成功上传,但onComplete内的警报不会出现,并且if语句内的html更新也不会出现.我在板上看到了其他类似的问题,但是这些建议对我没有用.具体来说,一些用户似乎在onComplete部分使用了其他格式:

The alert inside onComplete never comes up and the html update inside the if statement never appears although the file successfully uploads. I have seen other similar questions on this board, but the suggestions have not worked for me. Specifically, some users seem to use a different format for the onComplete section as:

.on('complete', function(event, id, fileName, responseJSON) {
            alert("Success: " + responseJSON.success);
            if (responseJSON.success) {
                 $('#files-upload').append('<img src="img/success.jpg" alt="' + fileName + '">');
            }

});

我不了解其中的区别或我应该使用的区别,并且无法在文档中找到任何帮助的内容.

I don't understand the difference or which I should be using and haven't been able to find anything in the documentation to help.

我对此东西有些陌生,因此任何帮助或建议都将不胜感激.谢谢!

I'm a little bit new to this stuff, so any help or suggestions would be greatly appreciated. Thanks!

推荐答案

Fine Uploader中的jQuery插件和非jQuery插件之间的事件处理程序有所不同.您正在使用jQuery插件,因此应将事件视为jQuery自定义事件,根据文档.

Event handlers work a bit differently between the jQuery plug-in and non-jQuery plug-ins in Fine Uploader. You are using the jQuery plug-in, so the events should be treated as jQuery custom events, per the documentation.

因此,您的代码应如下所示:

So, your code should look like this:

<script>
    $(document).ready(function () {
        $("#fine-uploader").fineUploader({
            request: {
                endpoint: 'upload2.php'
            },
            text: {
                uploadButton: 'Upload a file'
            }
        })
            .on('complete', function(event, id, fileName, responseJSON) {
                alert("completed");
                if (responseJSON.success) {
                    $('#imgPreview').html('Thumbnail:<img src="../images/test/' + fileName + '" alt="' + fileName + '">');
                }
           });

    });
</script>

这篇关于没有调用FineUploader OnComplete的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆