我想通过2个JavaScript字符串数组 “myArray1”和“myArray2”从ajax到webmethod。我所拥有的是以下不起作用。我不知道如何在data:
部分通过这些数组。传递多个数组; ajax到webmethod
C#部分代码。
public static string SavePage(List<string> myArray1, List<string> myArray2)
{
}
我想通过2个JavaScript字符串数组 “myArray1”和“myArray2”从ajax到webmethod。我所拥有的是以下不起作用。我不知道如何在data:
部分通过这些数组。传递多个数组; ajax到webmethod
C#部分代码。
public static string SavePage(List<string> myArray1, List<string> myArray2)
{
}
试试这个方法:
data: "{'myArray1':"+JSON.stringify(myArray1)+",'myArray2':"+JSON.stringify(myArray2)+"}",
在您的代码隐藏:
[System.Web.Services.WebMethod]
public static string SavePage(List<string> myArray1, List<string> myArray2)
{
return myArray1;
}
url: "mypage.aspx/SavePage",
data: { myArray1: myArray1, myArray2: myArray2 }
var data = {};
data.myArray1= myArray1;
data.myArray1= myArray2;
var json = JSON.stringify(data);
$.ajax({
...
data: json,
...
});
看一看这个http://www.aspsnippets.com/Articles /Send-and-Receive-JSON-objects-to-Web-Service-Methods-using-jQuery-AJAX-in-ASPNet.aspx – coder 2012-02-18 17:12:07