2010-09-26 91 views
4

我在我的MVC项目中使用jQuery表单插件进行图像上传。用Jquery表单插件上传图像不工作在IE8

的图片上传完美的作品在Chrome和Firefox,但是当涉及到IE 8

不喜欢Chrome浏览器,而不是返回稍后所消耗的JSON数据提交后回调,在IE 8则返回一个txt文件并询问你是否要下载。而在txt文件中,它是json数据。

无法弄清楚我做错了什么,有什么想法?

在此先感谢。

代码被放置在一个分离式的js文件: upload.js

(function ($) { 
ImageUploader = function (o) { 

     var options = { 


      success: showResponse, // post-submit callback 

      url: "/Image/ImageUpload",   // override for form's 'action' attribute 
      type:  "post",  // 'get' or 'post', override for form's 'method' attribute 
      dataType: 'json',  // 'xml', 'script', or 'json' (expected server response type) 
      clearForm: true  // clear all form fields after successful submit 

     }; 

     o.ajaxForm(options); 

     $("input#file").change(function() { 
      o.submit(); 
     }); 

// post-submit callback 
     function showResponse(responseText, statusText, xhr, $form) { 
     .... 
    } 
}; 
})(jQuery); 

在页面视图:

$(document).ready(function() { 
ImageUploader($("#ajaxUploadForm")); 
}); 

回答

2

好后痛苦通过我终于得到了我的解决方案互联网挖掘,非常乐意分享它:

jQuery Form Plugin根本没有问题。

问题是越野车IE 8无法很好地处理Json回调。即使你指定的类型为 “应用/ JSON”

解决方案:变化的内容类型从“应用/ JSON的” 到 “text/plain的” 在MVC JsonResult

return Json(newImage, "text/plain", JsonRequestBehavior.AllowGet); 
+0

我想你在ajax中指定Accept头参数为text/javascript(现在我可以记得)。这不是IE 8的错误,但功能:)内容类型告诉服务器你发送了什么,但你需要告诉它你期望的回报 – 2011-07-31 21:46:23