JavaScript-about the role of name in input?

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

I pass parameters like the one written above to the Java backend, where var1,var2 is I use $ ("#xx"). Val () Gets the contents of the input space, which is successfully obtained in the front end, but the backend is not retrieved correctly (input space does not have a name attribute).
My question is: in this case of using $.post () without form and submit, does the Name property inside the input control have any effect on the data transfer?

Reply content:

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

I pass parameters like the one written above to the Java backend, where var1,var2 is I use $ ("#xx"). Val () Gets the contents of the input space, which is successfully obtained in the front end, but the backend is not retrieved correctly (input space does not have a name attribute).
My question is: in this case of using $.post () without form and submit, does the Name property inside the input control have any effect on the data transfer?

No impact, this is an AJAX POST request, the name and value of the data has been indicated in the database, the background to obtain the name and the name x y of the data can be obtained var1 and var2

It doesn't matter if you have a form or a submit, you can spell the right thing in data. There was a Formdata object in the XHR, and the new one came out and filled in the data and sent it out in the same way.
But is it okay if you write like that? The string I am generally similar to the ' key=value&key2=value2 ' this way of writing, or the use of JSON {' key1 ': ' value1 ', ' key2 ': ' value2 '} This kind of writing, relative will insure some ...

  • 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.