AJAX FormData()与encodeURI()

jQuery uses the encodeURI(), so the data sent through AJAX is like this:

key1=true & key2=34 & ...

To send an image through AJAX, I use the FormData(), so the data from AJAX (without an image) is like:

-----------------------------7e136023611f0
Content-Disposition: form-data; name="key2"

34

Now I have two pure-JS functions for AJAX. The main one uses encodeURI(), and the other one is only for uploading images, using the new FormData().

As I want to have only one AJAX function, my question is - would it be reasonable so switch only to the FormData()? What's the reason for jQuery to use the encodeURI()?

jQuery $.ajax accepts an object as datastring, so you could pass on the url of the image, or also use something like:

data = 'data:image/gif;base64,R0lGODlhAAEwAMQAAJ2M5Me98GRK1D...1rTIIAQA7';

So you can then fetch and reconstruct the image on the other side.