1

我正在使用 uploadify 在我的 ASP.NET MVC 应用程序上上传 .csv 文件。从控制器操作中,我返回一个带有几个值的 JSON,如下所示:

return Json(new { success = false, message = result.Message });

以下是上传代码:

$("#email").uploadify(
                    {
                    'uploader': '/js/component/uploadify/uploadify.swf',
                    'script': '/email/UploadEmail',
                    'cancelImg': '/js/component/uploadify/cancel.png',
                    'fileExt': '*.csv',
                    'fileDesc': '*.csv',
                    'auto': true,
                    'multi': false,
                    'buttonText': 'Upload...',

                        'onComplete': function (event, queueID, fileObj, response, data)
                            {

                                alert(jQuery.parseJSON(response));
                                alert(jQuery.parseJSON(response.message));
                                var filename = fileObj.name;
                                $('#emailSuppressionFile').append('<input id="' + queueID + '" type="hidden" name="files[' + queueID + ']" value="' + filename + '" />');                                   
}                                
                    });

我正在尝试阅读从控制器操作返回的“消息”,但不知道如何。请参阅上面的警报。第一个警报返回:[object Object],第二个返回 null。

4

2 回答 2

3

试试这样:

onComplete: function(event, queueID, fileObj, response, data) {
    var json = jQuery.parseJSON(response);
    alert(json.message);
},

也不要在事件名称周围加上引号。

于 2012-10-02T15:58:53.317 回答
0

在旧版本的 Uploadify onComplete 事件中,用于从 Controller 提供响应。但是,在最新版本中,您需要使用 onUploadSuccess 事件,如下所示,

   'onUploadSuccess' : function(file, data, response) {
         alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
    }
于 2013-06-25T07:50:46.963 回答