Home > Web Front-end > JS Tutorial > body text

JavaScript sends parameters with the same attributes to the background, that is, array parameters_jquery

WBOY
Release: 2016-05-16 16:59:54
Original
1060 people have browsed it

When we transfer parameters, we often encounter parameters with the same attributes being transferred to the background. The best choice is to use an array. When we send it to the background, we only need to define and use the array normally in javascript and pass it to the background as a parameter:

Copy code The code is as follows:

var arry= new Array();

arry[0] = "102";

arry[1] = "103" ;

arry[2] = "104";

url = "test.jsp?arry=" arry;

Accepting method in the background:
[code]
String arry = request.getParmeter("arry");

String[] par = arry.split(",");
[code]
this At this time, par becomes an array in java. The value of arry is "102,103,104", which means that during the transmission process, the browser automatically converts the JavaScript array parameters into comma-separated strings. We only need to take out the string in the background and split it according to commas. It can be the corresponding array.

In addition, I have seen people using json on the Internet, but I don’t feel comfortable with it. The request.getParmeterValues ​​method is also useful. The specific usage is as follows:

Use the same parameter in the foreground and assign and pass it multiple times:

url="test.jsp?arry=102&arry=103&arry=104 "

Take out in the background:

String arry[] = request.getParmeterValues("arry");

The value of arry at this time is {102,103,104}

Choose the specific method according to your own habits!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!