js代码:
$(function () {
$("#btnTest").click(function () {
var array = new Array();
array.push("");
array.push("");
array.push("");
var ids = JSON.stringify(array);//格式为:[1,3,5]
$.ajaxSettings.async = false;
$.post("/Handler1.ashx", { ids: ids }, function (data) {
alert(data);
}).error(function () {
alert("请求出错");
});
});
});
Handler1.ashx代码:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string strIds = context.Request.Form["ids"];
//安装Json.NET
List<string> ids = JsonConvert.DeserializeObject<List<string>>(strIds);
context.Response.Write("ok");
}