jquery文件上传dataType脚本IE问题

时间:2012-01-25 03:02:29

标签: jquery internet-explorer file-upload

我仍然遇到使用jquery fileupload插件的麻烦,仅限于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

我将dataType指定为:'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 no ....

编辑:

IE未传递请求标头:

  X-Requested-With  XMLHttpRequest

1 个答案:

答案 0 :(得分:2)

我认为这回答了我的问题

  

forceIframeTransport

     

将此选项设置为true可强制iframe传输上传,即使是   浏览器能够上传XHR文件。这可能很有用   跨站点文件上传,如果是Access-Control-Allow-Origin标头   无法设置为所需的服务器端上载处理程序   跨站点XHR文件上传。

Type: boolean
Default: false

IE没有执行XHR请求...