首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >jquery插件'uploadify‘-如何从上传脚本返回响应?

jquery插件'uploadify‘-如何从上传脚本返回响应?
EN

Stack Overflow用户
提问于 2010-11-01 06:26:45
回答 4查看 10.6K关注 0票数 5

我的头部代码:

代码语言:javascript
运行
复制
$(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“文件中所能做的就是通过把文件移到最后的目录来完成上传过程;我不认为有任何方法可以像错误一样”返回一些东西“,对吧?

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

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

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-11-01 06:39:11

您可以将一些事件处理程序添加到上载脚本中,以检查完整的操作和错误

代码语言:javascript
运行
复制
$('#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

希望能有所帮助

票数 7
EN

Stack Overflow用户

发布于 2010-11-01 07:38:04

在add_list.php文件中回显的任何内容都将作为响应发送到onComplete函数。因此,您可以执行以下操作:

代码语言:javascript
运行
复制
$(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',
    'onComplete' : function(event,ID,fileObj,response,data) {
         alert(response);
      }
    });
});
票数 1
EN

Stack Overflow用户

发布于 2010-11-03 18:55:30

如果你想要文件名,你“必须”使用(正确的方法) fileObj.name:

代码语言:javascript
运行
复制
$(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',
    'onComplete' : function(event,ID,fileObj,response,data) {
         alert(fileObj.name);
      }
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4065477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档