jquery插件’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”文件中执行的AFAIK是通过将文件移动到最终目录来完成上传过程; 我不认为有什么办法可以像错误那样’回复’某些东西’吗?

如果我也可以使用这个文件来禁止某些字符或者如果出现某种问题则返回错误,那会很好,但我不认为有?

我想我可以删除任何不好的字符,但知道我是否能以某种方式返回响应会很有用吗?

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

 $('#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文档

希望能帮助到你

在add_list.php文件中回显的任何内容都将作为响应发送到onComplete函数。 所以你可以做到以下几点:

 $(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); } }); }); 

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

 $(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); } }); }); 

任何可能在将来遇到这种情况的人。 我花了一点时间弄清楚如何从服务器传回我自己的数据。

本文中当前版本的uploadify是3.2,您可能正在寻找onUploadSuccess事件: http ://www.uploadify.com/documentation/uploadify/onuploadsuccess/

这将允许您从服务器获取返回的数据。