Jquery ajax transmits an array in the background action

Source: Internet
Author: User

Jquery ajax transmits arrays to the background. The idea at the beginning was: directly var array = new Array (), and then assign this array to a parameter that needs to be passed to the backend when Ajax is used for submission. It seems that everything goes well. This is not the case. If you have any questions about the principle of http://www.iteye.com/problems/56240? All arrays transmitted to the background must be converted to strings. For example, if two name Information Names = aaaa name = bbb is a GET request, it can be converted to: http: // localhost/xxx? Name = aaa & name = bbb; for a POST request, the parameter cannot be directly written as param: {name = 'aaa', name = 'bbb '}. If you use this parameter, only the value of name = bbb will be obtained in the background. What should I do? My solution is to use List or array reception in the background. The foreground needs to use a js script to separate multiple identical parameters such as name, and assemble parameters through the "," separator to form a ", to the background. Example: jquery ajax and spring3 mvc: 1. html element <input name = "item" type = "checkbox" value = "2001"/> payment <input name = "item" type = "checkbox" value = "2002 "/> query <input name = "item" type = "checkbox" value = "2003"/> reconciliation <input name = "item" type = "checkbox" value = "2004 "/> withdrawal 2. jquery code var info = ""; var items = $ ('[name = "item"]: checkbox: checked'); for (var I = 0; I <items. length; I ++) {// If I + 1 is equal to the length of the option, add an empty character Otherwise, it is a comma (info + items. get (I). value) + (I + 1) = items. length )? '': ',');} $. Ajax ({type: 'post', url: "addPartnerInfo.html", dataType: 'text', data: {interface: info}, success: function (data) {alert (data) ;}}); java code @ RequestMapping (value = "/addPartnerInfo", method = RequestMethod. POST) public @ ResponseBody String addPartnerInfo (String [] interface) {System. out. println (interface); return "OK ";}

Related Article

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.