FineUploader OnComplete not being called

故事扮演 提交于 2019-12-12 05:37:34

问题


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>

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!


回答1:


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>


来源:https://stackoverflow.com/questions/18478100/fineuploader-oncomplete-not-being-called

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