Javascript-what is the role of name in input?

Source: Internet
Author: User
{Code ...} I used $ post to pass the parameter to the java background, where var1 and var2 are $ (& quot; # xx & quot ;). the content in the input space obtained by val () is obtained successfully at the front end, but the backend cannot be obtained correctly (the input space does not have the name attribute). my problem is: here...
$.post(    url : 'xxx',    data : "{x:var1,y:var2}",    function(msg){        alert(data);    },    type:'json')

I use $ post to pass parameters to the java background, where var1 and var2 are $ ("# xx "). the content in the input space obtained by val () is obtained successfully at the front end, but the backend cannot be obtained correctly (the input space does not have the name attribute)
My problem is:When $. post () is used without form and submit, does the name attribute in the input control affect data transmission?

Reply content:
$.post(    url : 'xxx',    data : "{x:var1,y:var2}",    function(msg){        alert(data);    },    type:'json')

I use $ post to pass parameters to the java background, where var1 and var2 are $ ("# xx "). the content in the input space obtained by val () is obtained successfully at the front end, but the backend cannot be obtained correctly (the input space does not have the name attribute)
My problem is:When $. post () is used without form and submit, does the name attribute in the input control affect data transmission?

This is an ajax post request. The data name and value have been specified in data.xAnd the name isyData can be obtained.var1Andvar2Now

It doesn't matter whether there is a form or submit. you just need to splice the items in data. There is a FormData object in XHR, and the new one is just as good as sending it in the east suit data.
But are you sure you want to write this? The string is generally written like 'key = value & key2 = value2', or the json {'key1': 'value1 ', 'key2 ': 'value2'} is relatively safe ......

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.