ASP.NET使用jQuery Ajax传递json数据,返回接收json的数据。
$.ajax({
url: "handle.ashx/GetEgg",
type: "POST",
dataType: "json",
async: true,
data: { id: 16,rid: '111'},
success: function (res) {
//debugger;
res = res[0];
if (1 == res.success) {
alert('success');
}
else {
alert('msg:'+res.msg);
}
},
error: function () { alert("出错"); }
});
asp.net 处理程序handle.ashx返回json代码:public string GetEgg()
{
//返回json的字符串
return "[{\"success\":\"1\",\"data\":{\"price\":\"88.8\"},\"msg\":\"success\"}]";
}
php,jsp同理