Php + html5 uses the FormData object to submit a form and upload an image. _ PHP Tutorial

Source: Internet
Author: User
Php + html5 uses the FormData object to submit a form and upload an image ,. Php + html5 uses the FormData object to submit a form and upload an image. This article describes how php + html5 uses the FormData object to submit a form and upload an image. I would like to share with you how to submit a form and upload images using the FormData object in php + html5,

This example describes how to submit a form and upload an image using the FormData object in php + html5. Share it with you for your reference. The specific analysis is as follows:

FormData object. you can combine the name and value of all form elements in form into a queryString and submit it to the background. When Ajax is used for submission, using the FormData object can reduce the amount of work required to splice queryString.

Use FormData object

1. create a FormData empty object and use the append method to add key/value

The code is as follows:

Var formdata = new FormData ();
Formdata. append ('name', 'fdipzone ');
Formdata. append ('gender', 'male ');

2. get the form object and pass it as a parameter to the FormData object

The code is as follows:


The code is as follows:

Var form = document. getElementById ('form1 ');
Var formdata = new FormData (form );

Use FormData to submit a form and upload a file:

The code is as follows:





FormData Demo

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.