나는 다음과 ASP.net 웹 방법이 있습니다jQuery Javascript의 Array 매개 변수로 ASP.net 웹 메서드를 호출하는 방법은 무엇입니까?
[WebMethod]
public static string SaveUserNew(string id, string[] roles)
{
doStuff(id, roles);
}
내가 jQuery를 자바 스크립트 코드에서이 코드를 호출하고있어,하지만 내가 배열을 전달하는 구문을 모른다. 일반적으로 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
}
});
내 의도는 내 웹 메소드에 배열을 전달할 경우 비슷한 스타일로 코드를 작성하는 것입니다 : 여기에 작동합니까 배열없이 코드 의 예입니다.
중복 가능성 (http://stackoverflow.com/questions/7971393/passing 사용해 -array-of-strings-to-webmethod-with-variable-of-arguments-of-jq) – weir