配列の文字列を返す WebMethod があります。
[WebMethod]
public static string[] GetDataFromServer()
{
return new string[] { "one", "two", "three" };
}
次のコードを使用して WebMethod を呼び出しています。
$.ajax({
type: "POST",
url: "MyPage.aspx/GetDataFromServer",
data: "{}",
success: function (msg) {
alert(msg.d);
},
error: function (x, e) {
alert("The call to the server side failed. " + x.responseText);
}
});
WebMethod は文字列の配列を返すため、 を呼び出すとalert(msg.d);
、配列のすべての要素が で区切られて取得されます,
。msg.d
セパレーターで分割できることは理解して,
いますが、それは良い習慣ではないと思います。結果の配列のさまざまな要素にインデックスでアクセスするにはどうすればよいですか?