How to implement asynchronous file uploads
With the support of the file FileReader object, asynchronous file uploads will be simple. (The form was previously submitted to the IFRAME for implementation)
1: Get the File object
2: Read 2 binary data
3: Simulate HTTP requests, send data (usually troublesome here)
Sending data using the Sendasbinary method of the XMLHttpRequest object under Forefox;
4: Perfect Realization
Problems encountered
Currently only Firefox can upload files correctly. (Chrome can also take google.gears upload)
The file data read from Firefox and Chrome doesn't seem to be the same (I don't know if this is the reason for debugging the tool)
Chrome and other advanced browsers do not have the Sendasbinary method to send data only using the Send method, which may be the reason for the failure to upload correctly. (Test normal text files can be uploaded correctly)
<title>HTML5 file and FileReader</title>
(Drag the picture here) use FileReader to get the file base64 encoding
FileReader Object
var filereader = new FileReader ();
Filereader.onloadend = function () {
Console.log (this.readystate); It's supposed to be 2 this time.
Console.log (This.result); Read completion callback function, data saved in result
}
filereader.readasbinarystring (file);//start reading 2 binary data asynchronous parameter to file object
Filereader.readasdataurl (file); Read Base64
Filereader.readastext (file);//Read text information
You can run the following simple example (Chrome and Firefox are available)
http://www.bkjia.com/PHPjc/444779.html www.bkjia.com true http://www.bkjia.com/PHPjc/444779.html techarticle How to implement asynchronous file uploads with the support of the file FileReader object, the asynchronous file upload becomes simple. (The form was previously submitted to the IFRAME for implementation) 1: Get File object 2: Read ...