Jquery 未调用uploadify onError
我们如何将自定义错误消息传递给uploadify 如果在控制器操作上出现异常(由try/catch捕获)-我们如何将其传递给uploadify脚本?从未调用onError事件Jquery 未调用uploadify onError,jquery,asp.net-mvc,uploadify,Jquery,Asp.net Mvc,Uploadify,我们如何将自定义错误消息传递给uploadify 如果在控制器操作上出现异常(由try/catch捕获)-我们如何将其传递给uploadify脚本?从未调用onError事件 [HttpPost] public ActionResult Upload(HttpPostedFileBase fileData, FormCollection forms) { try { if (fileData.Cont
[HttpPost]
public ActionResult Upload(HttpPostedFileBase fileData, FormCollection forms)
{
try
{
if (fileData.ContentLength > 0)
{
var statusCode = Helper.UploadList();
if (statusCode.Equals(System.Net.HttpStatusCode.Created))
return Json(new { success = true });
}
}
return Json(new { success = false });
}
catch (Exception ex)
{
return Json(new { success = false });
}
}
'onComplete': function (event, queueID, fileObj, response, data) {
if (response == '{"success":true}') {
alert("File uploaded successfully.");
}
else if (response == '{"success":false}') {
alert('File failed to upload. Please try again!');
}
else {
$("#file_uploadDomain").uploadifyCancel(queueID);
}
return false;
},
'onError': function(event, ID, fileObj, errorObj) {
alert(errorObj.type + ' Error: ' + errorObj.info);
},
编辑
应该可以帮助您在uploadify中使用JSON解决问题。要使JSON.parse正常工作,您需要包含或等效的文件
类似的东西应该可以使用——使用JSON对您有利
[HttpPost]
public ActionResult Upload(HttpPostedFileBase fileData, FormCollection forms)
{
try
{
if (fileData.ContentLength > 0)
{
var statusCode = Helper.UploadList();
if (statusCode.Equals(System.Net.HttpStatusCode.Created))
return Json(new { success = true });
}
}
return Json(new { success = false, message = "No file was specified." });
}
catch (Exception ex)
{
return Json(new { success = false, message = ex.ToString() });
}
}
'onComplete': function (event, queueID, fileObj, response, data) {
var json = JSON.parse(response);
if (json.success) {
alert("File uploaded successfully.");
}
else if (!json.success) {
alert(json.message);
}
//not sure what else you could have here for the value of success
//, thus a redundant else statement, but I will leave it in.
else {
$("#file_uploadDomain").uploadifyCancel(queueID);
}
return false;
},
那会容易得多。。。但是onComplete.data.success和data.message中未定义response.successundefined@GoldenUser-看看这些补充是否能让你朝着正确的方向前进