我有以下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