onComplete and onCompleteAll events failing to fir

2020-02-09 10:04发布

I have been using uploadify (www.uploadify.com) to upload images to my website, and it works beautifully until you try to expand on it a little. Im trying to get it to remove a queued up file from the list once that file has been uploaded. To do this, you would initialize uploadify as such:

            $("#fileUpload").uploadify({
            'uploader': '/scripts/uploadify.swf',
            'cancelImg': '/images/cancel.png',
            'script': '/Album/Manage/',
            'fileDesc': 'Image Files',
            'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
            'multi': true,
            'auto': false,
            'simUploadLimit': 3,
            'scriptData': {'album_id':'7'},
            onComplete: function(event, queueID, fileObj, response, data){
                alert(queueID); 
            }
        });

In the above example, you'd replace alert(queueID) with $("#fileUpload").uploadifyCancel(queueID) - I just have the alert to let me know when the event fires - which never happens. I have used IE and Firefox and no difference in either. Does anyone have any experience with this?

4条回答
我只想做你的唯一
3楼-- · 2020-02-09 10:53

For those who are using Macs use HTTP Scoop to view the request as Firebug does not show it. More on HTTP Scoop from this blog.

查看更多
家丑人穷心不美
4楼-- · 2020-02-09 11:04

RESOLVED!

Right, i gather this is about the only article on the entire internet (including the Uploadify documentation and support pages) that describes the quirks of Uploadify in a .Net MVC application

Having done extensive testing, I have seen that:

  1. If the script that accepts the uploaded files (specified in the uploadify initialize code as 'script': '/Album/Manage/') does not return anything, Uploadify's response events dont fire - I gather that an error stops it processing. My script was an action in a controller whose return type was string. If there was an error, it returned the error as a string, otherwise returned nothing. All I did to fix this was make it return 'OK' if nothing went wrong instead of nothing.

  2. Passing script data (specified in the uploadify initialize as 'scriptData': {'album_id':'7'}) the way I was doing it was ALSO causing an error - I havent worked out why (and RonnieSan, the father of Uploadify, didnt seem to see anything wrong with it) so if anyone does know maybe they can respond to this post

  3. You MUST NOT put single quotes around the event handlers e.g. onComplete: function(event, queueID, fileObj, response, data) { ... }

Hope this helps - if anyone needs assistance with .Net MVC implementation, just drop me a message.

查看更多
我只想做你的唯一
5楼-- · 2020-02-09 11:05

I have been using uploadify in an .NET MVC Application as well. And I know exactly what you mean. All I did to fix your problem was make my controller's action return a JSON response and I could parse it back on the onComplete event. The only time I had a problem with events were if the actual file is missing (as I display thumbnails of the image) on the response.

查看更多
登录 后发表回答