脚本:
function show() {
$.ajax({
type: "post",
async: false,
contentType: "application/json",
url: "/WebForm1.aspx/GetStr",
data: '{"name":"txxx"}',
dataType: "json",
success: function (result) {
debugger;
var data = $.parseJSON(result.d);
alert(data.name);
}
});
}
后台:
[WebMethod]
public static string GetStr(string name)
{
return "{"name":"" + name + ""}";
}
注意:[WebMethod(EnableSession=true)] 在方法内可以使用Session