ajax post json格式返回

Ajax.aspx:

Response.ContentType = "application/json";
Response.Write("{result: '" + Request["Name"] + ",你好!(这消息来自服务器)'}");

$.post("Ajax.aspx", { Action: "post", Name: "lulu" },
		function (data, textStatus){
			// data 可以是 xmlDoc, jsonObj, html, text, 等等.
			//this; // 这个Ajax请求的选项配置信息,请参考jQuery.get()说到的this
			alert(data.result);
		}, "json");


如果设置 "json"---后端必须返回
1.设置"application/json";
2.返回格式 "{result: '你好!(这消息来自服务器)'}"
3.前端直接用对象
data.result

猜你喜欢

转载自www.cnblogs.com/mmbbflyer/p/9927775.html