【C#】jQuery使用 $.post提交json数据

首先:
在1.4里,对json的格式非常严格,属性和值都得用引号引起来,而且必须是双引号,单引号也不行,格式如下
[ { "name": "simon", "gender": "男"},{"name": "jack","gender": "男" } ]
以后在jQuery的1.4版本里使用json时就要注意了。还有$.ajax方法中对json的一点改变,以前dataType:json正常,现在“json”要大写,dataType:JSON,不然就会执行error()了。

js代码:(如果参数值是中文,需要用escape(参数)进行编码。)
$.post('url地址', {
//参数
num1: 参数1,
num2: 参数2,
num3:参数3
},
//回调函数
function (theback) {
//输出结果
alert(theback.p);
},
//返回类型
"json");
c#代码:
context.Response.ContentType = "application/json";
//接受参数,进行操作。。。
//同样要对中文参数进行解码
context.Response.Write("{\"p\":\"11\",\"s\":\"22\"}");

原文地址:https://www.cnblogs.com/zhxhdean/p/2070529.html