jquery 插件 'uploadify' - 从上传脚本返回响应的方法?

标签 jquery jquery-plugins uploadify

我的标题代码:

$(document).ready(function() {
    $('#sampleFile').uploadify({
        'uploader': 'include/uploadify/uploadify.swf',
        'script': 'add_list.php',
        'scriptData': {'mode': 'upload'},
        'fileDataName': 'sampleFile',
        'folder': '/work/avais/bizlists/lists',
        'cancelImg': 'include/uploadify/cancel.png',
        'queueID': 'sampleQueue'
    });
});

据我所知,我在“add_list.php”文件中所能做的就是通过将文件移动到最终目录来完成上传过程;我认为没有任何方法可以“返回某些内容”,比如错误,对吗?

如果我也可以使用此文件来禁止某些字符或在出现某种问题时返回错误,那就太好了,但我认为不存在?

我想我可以去掉任何坏字符,但是知道我是否可以以某种方式返回响应会很有用吗?

最佳答案

您可以向上传脚本添加一些事件处理程序,以检查操作是否完整以及是否有错误

$('#sampleFile').uploadify({
        'uploader': 'include/uploadify/uploadify.swf',
        'script': 'add_list.php',
        'scriptData': {'mode': 'upload'},
        'fileDataName': 'sampleFile',
        'folder': '/work/avais/bizlists/lists',
        'cancelImg': 'include/uploadify/cancel.png',
        'queueID': 'sampleQueue'

    onComplete: function (event, queueID, fileObj, response, data) {
        // A function that triggers when a file upload has completed. The default 
        // function removes the file queue item from the upload queue. The 
        // default function will not trigger if the value of your custom 
        // function returns false.
        // Parameters 
        //    event: The event object.
        //    queueID: The unique identifier of the file that was completed.
        //    fileObj: An object containing details about the file that was selected.
        //    response: The data sent back from the server.
        //    data: Details about the file queue.
    },

    onError: function (event, queueID, fileObj, errorObj) {
        // A function that triggers when an error occurs during the upload process. 
        // The default event handler attaches an error message to the queue item 
        // returning the error and changes it's queue item container to red.
        // Parameters 
        //    event: The event object.
        //    queueID: The unique identifier of the file that was errored.
        //    fileObj: An object containing details about the file that was selected.
        //    errorObj: An object containing details about the error returned.
    }

});

因此,由于 onComplete 函数将从服务器端脚本发回响应,因此您可以将响应返回给客户端,然后在事件处理程序中解析该响应。

检查Uploadify documentation了解更多详情

希望对你有帮助

关于jquery 插件 'uploadify' - 从上传脚本返回响应的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4065477/

相关文章:

javascript - 单击链接的文本

javascript - 如何对每个克隆表单使用相同的功能

jquery - jQuery Ajax 请求不显示状态代码

javascript - 如何访问 jBox 中当前附加的 jBox 元素?

javascript - 如何显示加载...直到整个向导加载到 jQuery-steps 插件中?

JQuery DatePicker,如何高亮显示当前输入值日期?

javascript - 为什么我的 jQuery 插件在多个选择器上失败?

javascript - 使用经典 ASP 上传

Javascript 停止运行且没有错误消息

jquery - uploadify按钮在IE中不显示上传按钮