jquery文件上传 - IE做回调data.result问题 [英] jquery file upload - IE done callback data.result issue
问题描述
我正在使用 jQuery
文件上传插件 。
我不使用 UI
部分,只有基本的一部分。
当我执行以下操作时,出现 IE
的问题:
<$ p ($ data $)$ $ $ $ $''$ file $'$'$'$'$'$'$'$' (data.result!= null&& $ .trim(data.result)!='')
$('a#attachment')。html(data.result);
}
// ......................
在 IE中
data.result
是 Object
( IE9
至少,不知道其他人是什么...)
创意? 问题,我想我t是由于XHR文件上传在IE中不支持(甚至是9)。这是我相信正在发生的事情和我的解决方案: 由于Safari 5+,Firefox 4+和Chrome支持XHR文件上传,因此fileupload插件可以真正地将文件异步,允许来自服务器的纯文本响应。这个纯文本响应可以通过 我的解决方案: 我将 在您的情况下,我认为代码看起来像这样: 这里还需要注意的是,来自我的服务器的响应的内容类型是'text / plain',正如您可能已经注意到的,IE有时会提示用户保存或打开一个JSON响应。 以下是解决问题时有用的几个链接: 希望这有助于! I'm using I don't use the When I do the following, I'm having an issue in on On Ideas? I just ran into the same problem, and I think it is due to the fact that XHR file uploads are not supported in IE (even 9). Here's what I believe is happening, and my solution: Since Safari 5+, Firefox 4+, and Chrome support XHR file uploads, the fileupload plugin can transfer the files truly asynchronously, allowing for a pure text response from the server. This pure text response is available via In IE, however, the file transfer occurs via a full page refresh in a hidden iframe, causing Not only does this make it a pain to get to the data in IE, it makes the way you get to the data different between browsers. My solution: I set the In your case, I think the code would look something like this: Also important to note here is that the Content Type of the response from my server is 'text/plain'. As you may have noticed, IE sometimes prompts the user to save or open a json response. Here are a couple links that proved useful when resolving the problem:
https://github.com/blueimp/jQuery-File-Upload/wiki/Browser-support (see 'XMLHttpRequest' section at bottom)
https://github.com/blueimp/jQuery-File-Upload/wiki/Options (see 'forceIframeTransport' about 1/3 of the way down) Hopefully this helps! 这篇关于jquery文件上传 - IE做回调data.result问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Chrome /
Firefox 只是响应
Text
)。
done
事件处理程序中的 data.result
获得,并且可以很容易地使用。在IE中,文件传输是通过在隐藏的iframe中进行全页面刷新,导致 data.result
in done
处理程序是一个完整的文档
对象,响应文本深深地包含在< ; html>< body>< iframe>< pre>< / code>标记 这不仅会让人感到痛苦在IE中的数据,它使得你得到不同的浏览器之间的数据。
forceIframeTransport
选项设置为true,这使得所有浏览器都使用隐藏的iframe来传输文件,如IE。不幸的是错过了XHR文件上传,但是这至少给了我们在所有浏览器中的同样的响应。然后,在我的 done
处理程序中,我从文档
对象中提取结果,如下所示:
var result = $('pre',data.result).text();
$('input#fileupload')。fileupload({
forceIframeTransport:true,
url:'/ upload',
done:function(e,data){
var result = $('pre',data.result).text();
if(result!= null&& $ .trim (result)!='')
$('a#attachment').html(result);
}
...
https://github.com/blueimp/jQuery-File-Upload/wiki/Browser-support (请参阅'XMLHttpRequest'部分在底部)
https://github.com/blueimp/jQuery-File-Upload/wiki/Options (参见'forceIframeTransport'about三分之一的下降)
jQuery
file upload plugin.UI
part, only basic one.IE
:$('input#fileupload').fileupload({
url: '/upload',
done: function (e, data) {
if(data.result != null && $.trim(data.result) != '')
$('a#attachment').html(data.result);
}
//......................
IE
the data.result
is an Object
(IE9
at least, not sure the others...)Chrome
/Firefox
is just the response Text
(simple plain text from the server).data.result
in the done
event handler, and can be used easily.data.result
in the done
handler to be a full document
object, with the response text wrapped deep inside <html><body><iframe><pre>
tags.forceIframeTransport
option to true, which makes all browsers transfer files with a hidden iframe, like IE. It's unfortunate to miss out on XHR file uploads, but this at least gives us the same kind of response in all browsers. Then, in my done
handler, I extracted the result from the document
object like so:var result = $( 'pre', data.result ).text();
$('input#fileupload').fileupload({
forceIframeTransport: true,
url: '/upload',
done: function ( e, data ) {
var result = $( 'pre', data.result ).text();
if( result != null && $.trim( result ) != '' )
$( 'a#attachment' ).html( result );
}
...