我有以下ASP.net Web方法:如何使用jQuery Javascript中的数组参数调用ASP.net web方法?
[WebMethod]
public static string SaveUserNew(string id, string[] roles)
{
doStuff(id, roles);
}
我打电话从jQuery的Javascript代码的代码,但我不知道传递一个数组的语法。通常情况下,我写jQuery代码来调用网页方法,看起来像这样:
$.ajax({
type: "POST",
url: "someUrl.aspx?webmethod",
data: '{"foo":"fooValue"}',
contentType: "application/json;",
dataType: "json",
}
请阐明这一点。
更新:这里是没有阵列,做工作的代码一个例子:
[WebMethod]
public static string SaveUserNew(string id)
{
return "0";
}
var jdata = '{ "id": "3TWR3"}';
$.ajax({
type: "POST",
url: "UserMgmt.aspx/SaveUserNew",
data: jdata,
contentType: "application/json;",
dataType: "json",
traditional: true
}
});
我的本意是写一些代码以类似的风格,我传递数组到我的Web方法。
可能重复(http://stackoverflow.com/questions/7971393/passing -array-of-strings-to-webmethod -with-variable-number-of-arguments-using-jq) – weir 2014-06-18 17:17:40