The general handler returns json, and the program returns json
General handler:Public void ProcessRequest (HttpContext context) {string action = context. request. params ["action"]; switch (action) {case "TestAction": GetJsonString (); break;} context. response. contentType = "text/plain";} public void GetJsonString () {Product product = new Product (); product. name = "Apple"; product. expiry = new DateTime (2008, 12, 28); product. sizes = new string [] {"Small"}; List <Product> list = new List <Product> (); for (int I = 0; I <12; I ++) {list. add (product);} HttpContext. current. response. write (JsonConvert. serializeObject (new {Result = 1, Msg = "Data retrieved", Data = list }));
}
Loading js for the first time: $ (function () {$. ajax ({type: "get", url: "/action/Handler. ashx ", data: {action:" TestAction "}, dataType:" json ", success: function (data) {alert (data. result); alert ($. isArray (data. data) ;}, error: function (XMLHttpRequest, textStatus, errorThrown) {alert (XMLHttpRequest. status); alert (XMLHttpRequest. readyState); alert (textStatus );}});})