Problems with using Jquery.ajax to upload a form with files _jquery

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.