亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Asp.net實(shí)現(xiàn)無刷新調(diào)用后臺(tái)實(shí)體類數(shù)據(jù)并以Json格式返回

 更新時(shí)間:2016年12月08日 14:32:50   作者:扯  
本文主要分享了Asp.net實(shí)現(xiàn)無刷新調(diào)用后臺(tái)實(shí)體類數(shù)據(jù)并以Json格式返回的具體實(shí)例方法,具有一定的參考價(jià)值,有需要的朋友可以看下

新建一般處理程序

public class Temp
{
  public int Index { get; set; }
  public string Description { get; set; }
  public string ImagePath { get; set; }
  public DateTime MyDate { get; set; }
}

//數(shù)據(jù)源 
 List<Temp> listTemp = new List<Temp>()
 {
   new Temp(){ Index=1,ImagePath="Desert.jpg", Description="圖片1",MyDate=DateTime.Now},
   new Temp(){Index=2,ImagePath="Chrysanthemum.jpg", Description="圖片2",MyDate=DateTime.Now},
   new Temp(){Index=3,ImagePath="Penguins.jpg", Description="圖片3",MyDate=DateTime.Now},
   new Temp(){Index=4,ImagePath="Jellyfish.jpg", Description="圖片4",MyDate=DateTime.Now},
   new Temp(){Index=5,ImagePath="Tulips.jpg", Description="圖片5",MyDate=DateTime.Now}
 };
 
 public void ProcessRequest(HttpContext context)
 {
   string index = context.Request["Index"];
   string jsonStr = string.Empty;
   foreach (var item in listTemp)
   {
     if (item.Index.ToString() == index)
     {
       JavaScriptSerializer serializer = new JavaScriptSerializer();
       jsonStr = serializer.Serialize(item); //序列化為json格式
       break;
     }
   }
 
   context.Response.Write(jsonStr);
 }

前臺(tái)JS代碼

$.getJSON("imageChange.ashx", { Index: i - 1 }, function (result) {
  $("#<%=lblDescription.ClientID %>").text(result.Description);
$("#<%=Image1.ClientID %>").attr("src", path + result.ImagePath.substr(result.ImagePath.lastIndexOf('/') + 1));
 
  var d = eval("new " + result.MyDate.replace(/\//g, ""));
          $("#<%=lblDate.ClientID %>").text(Todate(d.ToLocalTime().toString()));
});

前臺(tái)JS代碼
//ToLocalTime()將UTC格式數(shù)據(jù)轉(zhuǎn)換成標(biāo)準(zhǔn)日期格式
//注意JavaScriptSerializer會(huì)將日期序列號(hào)為自1970年1月1號(hào)的刻度值,所以js獲取的時(shí)間值需做一些處理轉(zhuǎn)換成標(biāo)準(zhǔn)日期格式
//詳見http://msdn.microsoft.com/zh-cn/library/system.web.script.serialization.javascriptserializer.aspx

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論