In the project need to use Ajax to pass the array data, and in the background with a list of objects to receive, the main problem is how to construct data transmission, in the same way as the common Ajax pass character data, the code is written as follows
JS Code:
var righttypes=["A", "B", "C"];
var regioncode= "";
$.ajax ({
type: POST),
URL: "/service/lsprtapi.asmx/getstaticbyrighttypesandregioncode",
dataType: ' JSON ',
data:{"righttypes": Righttypes, "Regioncode": Regioncode},
contentType: "Application/json; Charset=utf-8 ",
success:function (data) {
var src = json.parse (DATA.D);
},
error:function () {
}
});
Observe the data passed in the browser as shown above:
The data passed by the "&" connection, is not the desired result, after consulting the data, modify the data as follows:
Data:JSON.stringify ({"Righttypes": Righttypes, "Regioncode": Regioncode})
Background code:
[WebMethod]
public string Getstaticbyrighttypesandregioncode (list<string> righttypes, string regioncode)
{
int Icount=righttypes. Count;
Return "Success";
}
After testing, the data can be normally obtained, for the use of Ajax to pass the array and objects and other complex data content, you can refer to the blog, a more comprehensive introduction
http://cnn237111.blog.51cto.com/2359144/984466