Detailed explanation of Ajax passing array parameter value to the server

小云云
Release: 2017-12-29 11:24:29
Original
4078 people have browsed it

When using MVC, sometimes you need to pass an array as a parameter value when sending a POST request to the server. The following is an example code to introduce to you the method of jQuery Ajax passing array parameter values to the server. Let's take a look. I hope it can help. to everyone.

The following examples are used to illustrate, first look at Action


[HttpPost] public ActionResult Test(List model) { return Json(null, JsonRequestBehavior.AllowGet); }
Copy after login

Method 1, construct the form element, and then call the serialize() method to get the construction parameter string


@{ Layout = null; }     Test 
  

Copy after login

Debug mode monitoring parameters, when the button is clicked, the monitored parameters are as follows

Method 2: Use JavaScript objects as parameters to pass values. The parameter name is the parameter name corresponding to the Action method, and the parameter value is a JavaScript array


@{ Layout = null; }     Test 
  

Copy after login

Method 3, use Json as parameter request, at this time Ajax needs to declare Content-Type as application/json


@{ Layout = null; }     Test 
  

Copy after login

The above example uses ASP.NET MVC 5

Related recommendations:

How to use php to pass arrays to js scripts

jquery ajax fails to pass arrays to the background

jquery ajax passes arrays to the background and Detailed explanation of how to receive array code in the background

The above is the detailed content of Detailed explanation of Ajax passing array parameter value to the server. For more information, please follow other related articles on the PHP Chinese website!

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
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!