I have a little problem. From webmethod returned two dimensional array.
My webmethod:
[WebMethod]
public static string[,] Test()
{
string[,] arry1 = new string[2, 2];
arry1[0, 0] = "test00";
arry1[0, 1] = "test01";
arry1[1, 0] = "test10";
arry1[1, 1] = "test11";
return arry1;
}
in my js code im using this way....
var arry1=new Array();
$.ajax({
url: "test.aspx/Test",
data: {},
cache: false,
async:false,
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "GET",
success: function (data) {
arry1 = data.d;
},
error: function (response) {
alert(response);
}
});
alert(arry1[1,1]); //test01 why not test11?
How can i do this?
Edit.. Array
"test00" "test01";
"test10" "test11";
in asp.net
arry1[0, 0] = "test00";
arry1[0, 1] = "test01";
arry1[1, 0] = "test10";
arry1[1, 1] = "test11";
in javascript
arry1[0] // test00
arry1[1] // test01
arry1[2] // test10
arry1[3] // test11
Based on your array running alert(arry1[1,1]);
would just return the value at position 1 which in the case of JavaScript, is an array, so your result will be ,test01
if you wanted to get test11
, you would have to do alert(arry1[3][1]);
, which would get the fourth position in the array [3]
, and then the value at [1]
of that array.
//What your array might like in JS
var arry1 = [[null,"test00"], [null,"test01"], [null,"test10"], [null,"test11"]];
alert(arry1[1,1]); // test01
alert(arry1[3][1]); // test11