後台代碼如下:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; HttpRequest request = context.Request; if (request.InputStream != null && request.InputStream.Length > 0) { StreamReader reader = new StreamReader(request.InputStream); string json = reader.ReadToEnd(); //接下來就是使用Newtonsoft.Json解析json字符串 //JsonConvert.DeserializeObject<CommonTableParam>(json);
//然後就可以使用前台傳給後台的Json數據了 } }
前端代碼如下: function extendAjaxParam(newSrc) { var src = { type: "post", dataType: "json", contentType: "application/json;charset=utf-8", error: function(err) { alert(err.responseText); } } return $.extend({}, src, newSrc); } $.ajax(extendAjaxParam({ url: 自定義的url, // data: JSON.stringify({ "id": id, "name": name }), success: function(data) { } }));