如何触发Uploadify onError事件处理程序? [英] How to trigger Uploadify onError event handler?

查看:173
本文介绍了如何触发Uploadify onError事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Uploadify 上传文件.问题是,在处理这些文件时,我需要通知用户任何错误.

I am using Uploadify to upload files. Problem is, I need to inform users of any error during processing of those files.

Uploadify具有onErroronCompleteonAllComplete事件处理程序,但是我不知道如何触发这些事件,以便使用户知道发生了什么.

Uploadify has onError, onComplete, and onAllComplete event handler but I do not know how to trigger these events so that users are informed of what is going on.

我需要发送JSON字符串吗? 此处此处

Do I need to send JSON string? There is a clue here and here and here but I couldn't make it to work. Perhaps the posting in the forum is outdated.

有人知道任何适用于Uploadify 2.1的示例吗?

Anyone got any example that works for Uploadify 2.1?

推荐答案

这使我丧命,但我找到了一种方法.在uploadify.php文件中,我创建了所有验证.区别在于,我为每种错误类型设置了HTTP 4xx代码.

This was killing me but I found a way. In the uploadify.php file I created all my validation. The difference here is that I set HTTP 4xx codes for each type of error.

if (! in_array($fileParts['extension'], $typesArray)) {
    header("HTTP/1.1 405"); //any 4XX error will work
    exit();
}

这会将"405"错误返回给uploadify.js.

This throws the "405" error back to uploadify.js.

在文件中,我设置了$(#fileInput").uploadify()我添加了"onError"功能.

In the file I set $("#fileInput").uploadify() I added the "onError" function.

        'onError' : function(event, ID, fileObj, errorObj) {
        var r = "<br />ERROR: ";
        switch(errorObj.info) {
        case 405:
            r += "Invalid file type.";
            break;
        case 406:
            r += "Some other error.";
            break;
        }

        setTimeout('$("#fileInput'+ ID + 'span.percentage").html("'+r+'");',111);
    }

这会强制在存在某种扩展功能的情况下存在uploadify默认功能.

This forces the uploadify default function to exist while kind of extending it.

希望获得帮助!

这篇关于如何触发Uploadify onError事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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