IE + jQuery.Form +多部分+ JSON响应= IE浏览器尝试下载响应 [英] IE + jQuery.Form + multipart + json response = ie tries to download response
问题描述
我试图用它通过jQuery.Form插件一个文件
字段提交一个表单,这里的code:
I'm trying to submit a form with a file
field in it via jQuery.Form plugin, here's the code:
$('form').ajaxSubmit({
url: "/path",
dataType: "json",
contentType: "multipart/form-data"
...
,服务器然后返回JSON作为响应。除了IE浏览器,它试图下载响应,文件中的所有浏览器的伟大工程。如果我从表格中删除文件领域,它也工作得很好。
The server then returns json as a response. Works great in all browsers except IE, which tries to download the response as a file. If I remove the file field from the form, it also works just fine.
我在这里,并在谷歌看到的各种解决方案,基本上试图描述,包括设置加密类型为通过jQuery的形式几乎是万能的,但没有奏效。
I've seen various solutions here and in Google and basically tried almost everything described, including setting enctype for the form via jQuery, but it didn't work.
任何建议将非常欢迎。
推荐答案
我还没有找到一个直接的解决办法,但我最终还是采取了以下措施:我用数据类型:文本
我在阿贾克斯的设置,然后从控制器返回的明文,分离与值;
和解析他们在客户端。这样,IE和Forefox不再试图下载一个响应。
I have not found a direct solution to this, but I eventually implemented the following workaround: I used dataType: "text"
in my ajax settings and then returned plaintext from controller, separating values with ;
and parsing them on the client side. That way IE and Forefox stopped trying to download a response.
我没有发现任何其他方式prevent所述行为等,然后返回明文。我试图返回JSON作为明文,然后用$ .parseJSON解析它,但它并没有因为一些JS错误工作。
I did not find any other way to prevent said behavior other then to return plaintext. I tried returning JSON as plaintext and then parsing it with $.parseJSON, but it didn't work due to some js errors.
这篇关于IE + jQuery.Form +多部分+ JSON响应= IE浏览器尝试下载响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!