1、从asmx文件返回,其实是字符串,需要特别处理
- function GetInfo() {
- $.ajax({
- type: "POST"
- , contentType: "application/json"
- , url: "pub.asmx/GetInfo"
- , data: "{'pId':'" + _PublicId + "','userId':'" + _UserId + "'}"
- , dataType: 'json'
- , success: function(data) {
- var json = eval('(' + data.d + ')');
- alert(json.flower + "," + json.egg + "," + json.isvote + "," + json.iskeep);
- }
- });
- }
C#:
- [WebMethod]
- public string GetInfo(int pId,int userId)
- {
- ……
- return String.Format(@"{{""flower"":""{0}"",egg:""{1}"",isvote:""{2}"",iskeep:""{3}""}}"
- , dr["flower"]
- , dr["egg"]
- , Convert.ToBoolean(dr["isvote"])
- , Convert.ToBoolean(dr["iskeep"]));
- }
参考文章