问题描述
我已经用这个技巧解决了
return Json(new { success = false, message = ex.Message }, "text/html");
现在就可以了。但是我能解释一下为什么它适用于text / html,而不适用于application / json和text / plain吗?首先是尝试下载JSON,其次是返回JSON字段的未定义属性。
解决方法
我试图从动作中返回Json,之后IE尝试下载它并显示保存对话框。我在Firefox中对其进行了测试,并且可以正常运行。
return Json(new { success = false,message = ex.Message },"application/json");
这种行为的原因是什么,我该如何解决?
之后在Javascript部分中我尝试
if (responseJSON.success == false) {
alert(responseJSON.message);
cancel();
}
但是IE仍然不会显示警报。它带给我保存对话框。
我尝试进行更改"application/json"
,"text/plain"
并且保存对话框消失了,但是还无法看到警报。我想念什么?
编辑:
这是我的全能Javascript,我使用Valums qquploader(ex-Ajaxupload)上传图片
var uploader = new qq.FileUploader({
element: document.getElementById("image-upload"),action: '/Home/ImageUpload',allowedExtensions: ['jpg','png','gif'],sizeLimlit: 2048,onComplete: function (id,fileName,responseJSON) {
if (responseJSON.success == false) {
alert(responseJSON.message);
cancel();
}
else {
alert("success");
//some code here
}
}
});
我alert("success");
在其他部分进行了测试,然后转发了json
"text/plain"
,之后我看到了警报。但是那段时间responseJSON.success != false
对我来说。您对此有何建议?