Home  >  Article  >  Web Front-end  >  jQuery encoding to convert base64 upload via AJAX

jQuery encoding to convert base64 upload via AJAX

php中世界最好的语言
php中世界最好的语言Original
2018-04-28 13:55:012031browse

This time I will bring you jQuery encoding conversion base64 upload through AJAX, jQuery encoding conversion base64 upload through AJAX What are the precautions, the following is a practical case, let's take a look.

The example in this article describes how jQuery encodes files into base64 and uploads them through AJAX. Share it with everyone for your reference, the details are as follows:

It is impossible to upload files directly using AJAX. Generally, a new iframe is created to complete the form submission process in it to achieve the effect of asynchronous file upload.

This can achieve better browser compatibility, but the amount of code will be relatively large, even if file upload plug-ins are used, such as plupload.

How can we achieve a level of flexibility? It would be great if we could treat files as ordinary form parameters just like ordinary AJAX submission of form data.

I had a flash of inspiration, wouldn’t it be enough to use the FileReader object of javascript to encode the file into base64 and then transmit it to the server~

Start doing it and have enough food and clothing. .

The front-end base64 encodes the file and transmits it to the server through ajax:


  

        

The back-end decodes and saves the file data:


I believe you have mastered it after reading the case in this article For more exciting methods, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the use of mapState and mapGetters in vuex

Detailed explanation of the steps to implement partial printing of the page in angular

The above is the detailed content of jQuery encoding to convert base64 upload via AJAX. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn