There are differences between IE and Firefox on the form enctype attribute.

Source: Internet
Author: User

There are differences between IE and Firefox on the form enctype attribute.In general, for dynamically created forms, if you want to upload files, you will naturally useCode:


1   // Create form
2   This . Form = Document. createelement ( " Form " );
3   This . Form. ID =   " Jasonuploadform " ;
4   This . Form. Name =   " Jasonuploadform " ;
5   This . Form. Method =   " Post " ;
6   This . Form. Action = Actiontarget;
7   This . Form. enctype =   " Multipart/form-Data " ;
8 Document. Body. appendchild ( This . Form );

 

This Code does not seem to be a problem on the surface, but it still cannot change the form encoding format in IE,

That is to say, the contenttype uploaded to the server is still: "application/X-WWW-form-urlencoded ".

But it can be correctly identified in Firefox, so that files can be uploaded normally.

So how can we make IE and Firefox correctly encode form data according to our requirements? After finding N for a long time, I finally found the solution, that is, simply specifying encoding and reading the following correct code:


1   // Create form
2   This . Form = Document. createelement ( " Form " );
3   This . Form. ID =   " Jasonuploadform " ;
4   This . Form. Name =   " Jasonuploadform " ;
5   This . Form. Method =   " Post " ;
6   This . Form. Action = Actiontarget;
7
8   // This. Form. setattribute ("enctype", "multipart/form-Data ");
9   This . Form. Encoding =   " Multipart/form-Data " ;
10
11 Document. Body. appendchild ( This . Form );

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.