jQuery文件上传dataType脚本在IE浏览器上的问题

3

我仍然在使用jquery文件上传插件时遇到问题,只有在IE浏览器上出现问题。

JavaScript代码如下:

$('input#fileupload').fileupload({
    url: '/upload_attachment.js',
    dataType: 'script',
 ................
 ................

$('input#realupload').bind('change', function(e){
   $('#fileupload').fileupload('send', {
    dataType: 'script',
    files: e.target.files || [{name: this.value}],
    fileInput: $(this)
 }); 
 e.preventDefault();       
});

这是请求头:

 Key    Value
 Request    POST /holdings/183400184/upload_attachment HTTP/1.1
 Accept text/html, application/xhtml+xml, */*
 Referer    http://192.168.1.209:3000/holdings/183400184
 Accept-Language    en-NZ
 User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
 Content-Type   multipart/form-data; boundary=---------------------------7dc1d02610132
 Accept-Encoding    gzip, deflate
 Host   192.168.1.209:3000
 Content-Length 196
 Connection Keep-Alive
 Cache-Control  no-cache
 Cookie xxxxxxxxxxxxxxx

我指定数据类型为:'script',并从服务器返回:

 Key    Value
 Response   HTTP/1.1 200 OK 
 Content-Type   text/javascript; charset=utf-8
 Cache-Control  max-age=0, private, must-revalidate
 X-Ua-Compatible    IE=Edge
 X-Runtime  4.625297
 Server WEBrick/1.3.1 (Ruby/1.9.3/2011-10-30)
 Date   Wed, 25 Jan 2012 02:52:48 GMT
 Content-Length 345
 Connection Keep-Alive
 Set-Cookie ******************

响应体如下:

var li = '<li>';
li += '<img alt="Paperclip" src="/images/paperclip.png?1323904510" /> ';
li += '<a href="/XXXXX/183400184/download_attachment/980191034">test.txt</a> <img alt="Cross_16x16" data_url="/XXXXX/183400184/destroy_attachment/980191034" src="/images/cross_16x16.png?1327452770" />';
li += '</li>';
$('ul#attachments').append(li);

在Chrome、Firefox等浏览器上一切都很好。
在IE上,它会问我是否要打开或保存update_attachment.js文件?其他的ajax调用都正常工作,正确解释JavaScript响应,只有使用fileupload时不行。
编辑:
IE没有传递请求头:
  X-Requested-With  XMLHttpRequest
1个回答

2

我认为这回答了我的问题

forceIframeTransport

将此选项设置为true以强制使用iframe传输上传,即使浏览器能够进行XHR文件上传。对于跨站点文件上传,如果无法为服务器端上传处理程序设置Access-Control-Allow-Origin标头以进行跨站点XHR文件上传,则可以使用此选项。

Type: boolean
Default: false

IE没有进行XHR请求...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接