[WebMethod] PublicList<picturemanager>Loadpictureone () {Datadatacontext context=NewDatadatacontext (); List<PictureManager> list =NewList<picturemanager>(); Try{List<PictureManager> li = context. Picturemanager.where (p = P.typeid = =2&& P.isshow = =true). OrderByDescending (p = p.id). Take (8). ToList (); foreach(Picturemanager Iteminchli) {picturemanager TB=NewPicturemanager (); 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 NewException (ex. Message); } returnlist; }
//Load Picture 1function Loadpictureone () {$ ("#div1"). HTML (""); varHtmlinfo =""; $.ajax ({type:"Post", ContentType:"Application/json;charset=utf-8", URL:".. /.. /service/backstageservice.asmx/loadpictureone", Data:"", DataType:"JSON", success:function (result) {vardata =eval (RESULT.D); $ (data). each (function () {Htmlinfo+="<div class= ' moxin ' ><div >"+ 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 +"\ ") ' ></li></ul></div>"; }); $("#div1"). HTML ($.trim (htmlinfo)); }, Error:function (err) {Layer.alert ("Error loading picture",5); } });}
If a single object is returned:
The value of RESULT.D is:"{" BRXM ":" AA "," ys ":" BB "," KS ":" CC "," HM ":" 123 "," SJ ":" 08:50 "}"
Eval ("(" +result.d+ ")") try it.
[WebMethod] Public stringGetCount () {stringJSON =string. Empty; Try { using(Datadatacontext context =NewDatadatacontext ()) { if(Context.tb_ApplicationAward.Count ()! =0) { intCountm = Convert.ToInt32 (context.tb_applicationaward.sum<tb_applicationaward> (p =p.schedulelength)); if(Countm > -) {Countm= -; } intCountpeople =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) {varobj = eval ('('+ JS.D +')'); varCountm = obj. Countm;//total number of metersCount =Countm; varCountpeople = obj. Countpeople;//Total number//The front desk is made with JS.D.
Asp.net_webservice return JSON