批量传递ID数组字符串到后台的处理

时间:2021-09-03 09:29:39

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");
}