Today to help people look at the code, encountered a little problem. When you use JQuery to upload a form with a file, there are some problems.
First, because you are using FormData, you must configure Processdata:false in the parameters passed in $.ajax.
Otherwise, the illegal invocation exception will be thrown because jQuery defaults to processing the data in the Incoming data field.
The Official document explains this:
Second, attention to the request of the Content-type header, the default is application/x-www-form-urlencoded; Charset=utf-8, which is what we usually see as the "a=a&b=b" format. But when you use FormData, you can't.
Add the ContentType field to the parameter and set its value to false. If the JQuery version is less than 1.6, it is manually set to Multipart/form-data. For specific instructions, see the documentation:
I used to use native XMLHttpRequest, so I've never had this problem before. Now that you have met, you have to solve it. So write it down for later searching.
The above is a small set to introduce you to the use of Jquery.ajax upload file with the form of the problem encountered, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!