Formdata general usage, mobile, PC-side can be used, PC has compatibility issues

Source: Internet
Author: User

Actually, Formdata is an object.
He is a relatively new thing (in fact, I do not know what to change the name of the good)

Using an FormData object, you can use a series of key-value pairs to simulate a complete form and then use the XMLHttpRequest "form" to send it.

Let me tell you about his usage:

First we're going to new a Formdate object,

For example: var date = new Formdate ();

In fact, I looked at the first glance, I thought it was JQ, because I saw a append haha, we can understand Xx.append (key,val), append there are 2 parameters.

For example: Data.append ("name", "Ye Ye");

We save more data so that we can upload the form using post in Ajax.

var XHR = new XMLHttpRequest ();

XHR = open ("POST", "address");

Xhr.send (date);

Ok!!!! Isn't it simple!

So what if we have more data, and we don't append in?

No! NONO ...

if: $scope. Params is an object that stores an object with a lot of data (key,val) in it, so

var data = new FormData ();
for (var i in $scope. Params) {
Data.append (i, $scope. Params[i]);
}

Isn't it simple again!

This data object, you can send to the backstage.

  

Formdata general usage, mobile, PC-side can be used, PC has compatibility issues

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.