[WebMethod] public List<PictureManager> LoadPictureOne() { dataDataContext context = new dataDataContext(); List<PictureManager> list = new List<PictureManager>(); try { List<PictureManager> li = context.PictureManager.Where(p => p.TypeId == 2 && p.IsShow == true).OrderByDescending(p => p.Id).Take(8).ToList(); foreach (PictureManager item in li) { PictureManager tb = new PictureManager(); tb.Id = item.Id; tb.Name = item.Name; tb.Picture = item.Picture; tb.Price = item.Price; tb.PriceInfo = item.PriceInfo; tb.Remark = item.Remark; list.Add(tb); } } catch (Exception ex) { throw new Exception(ex.Message); } return list; }
//加载图片1 function LoadPictureOne() { $("#div1").html(""); var htmlInfo = ""; $.ajax({ type: "post", contentType: "application/json;charset=utf-8", url: "../../service/backstageService.asmx/LoadPictureOne", data: "", dataType: "json", success: function (result) { var data = eval(result.d); $(data).each(function () { htmlInfo += "<div class=‘moxin‘><div ><img style=\"width:223px; height:217px;\" src=‘../../images/PictureManager/" + this.Picture + "‘ alt=‘" + this.Name + "‘ /></div><ul><li><p class=‘wenziqj‘>" + this.Price + "</p></li><li><p class=‘wenzish‘> " + this.PriceInfo + "</p><p class=‘wenzixia‘>" + this.Name + "</p></li><li class=‘tuliji‘ onclick=‘img_click(\"" + this.Name + "\")‘><img src=‘../../images/images/qiangoguanniu.png‘ style=‘cursor:pointer‘ /></li></ul></div>"; }); $("#div1").html($.trim(htmlInfo)); }, error: function (err) { layer.alert("加载图片出错", 5); } }); }
如果返回的 是单个对象:
result.d的值是:"{"brxm":"aa","ys":"bb","ks":"cc","hm":"123","sj":"08:50"}"
eval("("+result.d+")")试一试。
[WebMethod] public string GetCount() { string json = string.Empty; try { using (dataDataContext context = new dataDataContext()) { if (context.tb_ApplicationAward.Count() != 0) { int CountM = Convert.ToInt32(context.tb_ApplicationAward.Sum<tb_ApplicationAward>(p => p.scheduleLength)); if (CountM > 2000) { CountM = 2000; } int CountPeople = context.tb_ApplicationAward.Count(); return "{‘CountM‘:" + CountM + ",‘CountPeople‘:" + CountPeople + "}"; } return "{\"CountM\":" + 0 + ",\"CountPeople\":" + 0 + "}"; } } catch (Exception) { return null; } }
function Loading() { $.ajax({ type: "post", contentType: "application/json;charset=utf-8", url: "../../service/backstageService.asmx/GetCount", data: "{}", dataType: "json", success: function (js) { var obj = eval(‘(‘ + js.d + ‘)‘); var CountM = obj.CountM;//总米数 count = CountM; var CountPeople = obj.CountPeople;//总人数 //前台取得时候是用js.d来取
时间: 2024-10-25 06:02:52