cs代码:
[System.Web.Services.WebMethod]
public static string Method(string id,string t)
{
string ret= "{name:'广东',cities:{ city:['广州','深圳','珠海'] } }";
return ret;
}
aspx代码:
var $src = '{ id:"' + $id + '",t:"' + $t + '" }'; $.ajax({ type: "post",//要用post方式 contentType: "application/json",url: "WebMethod.aspx/Method",//方法所在页面和方法名 data: $src,// contentType: "application/json; charset=utf-8",dataType: "json",success: function (data) { var $val = data.d; var c = $val['name']; var json = eval('(' + $val + ')'); // var a = eval($val); var b = json['name']; },error: function (err) { alert(err); } });
原文链接:https://www.f2er.com/ajax/164154.html