最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Fallback AJAX file upload for Internet Explorer - Stack Overflow

programmeradmin1浏览0评论

I have implemented an AJAX file uploader in HTML5 using xHR2 and File api for an internal project. We were only required to support Firefox/Safari/Chrome. I used the following links as a reference

  1. /
  2. /

Now I am required to support Internet Explorer 10 and below. IE 10 supports XHR2 but File API support is lacking. Is there a way to detect that these APIs are not supported? If I can detect that the APIs are not supported, then how do I implement AJAX file upload for IE?

I am using Google Closure JS library not jQuery or any other library. The choice of library cannot be changed. Please use jQuery or some ones to that effect in the response. However, any code snippets that use jQuery are perfectly alright.

I have implemented an AJAX file uploader in HTML5 using xHR2 and File api for an internal project. We were only required to support Firefox/Safari/Chrome. I used the following links as a reference

  1. http://www.html5rocks./en/tutorials/file/xhr2/
  2. http://www.html5rocks./en/tutorials/dnd/basics/
  3. https://developer.mozilla/en-US/docs/Using_files_from_web_applications

Now I am required to support Internet Explorer 10 and below. IE 10 supports XHR2 but File API support is lacking. Is there a way to detect that these APIs are not supported? If I can detect that the APIs are not supported, then how do I implement AJAX file upload for IE?

I am using Google Closure JS library not jQuery or any other library. The choice of library cannot be changed. Please use jQuery or some ones to that effect in the response. However, any code snippets that use jQuery are perfectly alright.

Share Improve this question edited Feb 10, 2018 at 15:02 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Jan 4, 2013 at 8:06 KartikKartik 2,6192 gold badges40 silver badges62 bronze badges 1
  • 1 Ie 10's file api support is not lacking. You can upload files using xhr in ie10 without any issues. – Ray Nicholus Commented Jan 4, 2013 at 12:43
Add a ment  | 

3 Answers 3

Reset to default 3

probably the easiest way to detect if the File API exists is to

typeof File

In a browser that supports the File API it should return an object or function - Internet Explorer returns undefined

as far as how to fallback and make it work for all users

I've used this tool https://github./valums/ajax-upload that creates an iframe and posts the upload to the iframe and emulates an AJAX file upload - its all pure javascript no libraries required and supports all the way back to IE6

Recently I've been working on a file uploader to be used together with google closure library. I found the fine-uploader library a good start. It's not written with the closure library, but it provides me the basic guidelines: uses xhr to upload a file if supported, otherwise fallback to form post into a hidden iframe.

In my code, I implemented two classes: one uses a XMLHttpRequest to upload a file, and the other use goog.IframeIo's sendFromForm method to upload a file.

Take a look at the goog.iframeIo class in the Google Closure Library. This will take a file input element from a form and post it to an iFrame, giving the equivalent of an AJAX experience, even if it isn't in an actual XHR.

Here's a link to Google's documentation on how to implement it:

https://code.google./p/closure-library/source/browse/closure/goog/net/iframeio.js#48

发布评论

评论列表(0)

  1. 暂无评论