$.ajax倒计时
//限时抢购1NowTime.getTime() function getRTime() { //存储传过来的所有div的goodsid var goodids = ""; for (var i = 0;i < $('.xt23').length; i++) { goodids += $('.xt23').eq(i).attr("name") + "|"; }; $.ajax( { url: "Handler_times.ashx", type: "POST", data: { goodids: goodids }, datatype: "TEXT", success: function (data) { if(data!="") { var time = new Array(); time=data.split('|'); for (var i = 0; i < $('.xt23').length; i++) { $('.xt23').eq(i).text(time[i]); } } } }); } setInterval(getRTime, 1000);
一般处理程序
public void ProcessRequest (HttpContext context) { string ids1 = context.Request["goodids"].ToString(); string ids2 = ids1.Substring(0, ids1.Length - 1); string[] goodsid = ids2.Split('|'); string jj1 = ""; LXmallDBDataContext lx = new LXmallDBDataContext(); for (int i = 0; i < goodsid.Length; i++) { var query = lx.Goods_ID.Where(p => p.GoodsID == goodsid[i]).ToList(); if (query.Count > 0) { DateTime starttime = Convert.ToDateTime(query.First().StartTime); DateTime endtime = Convert.ToDateTime(query.First().EndTime); //日期时间格式相减 if (DateTime.Now >= starttime) { //求时间间隔 TimeSpan jj = endtime.Subtract(DateTime.Now); //string jj1 = jj.ToString("yyyy年MM月dd日hh时mm分ss秒"); jj1 += jj.Days + "天" + jj.Hours + "时" + jj.Minutes + "分" + jj.Seconds + "秒" + "|"; } else { TimeSpan jj = starttime.Subtract(DateTime.Now); jj1 += jj.Days + "天" + jj.Hours + "时" + jj.Minutes + "分" + jj.Seconds + "秒" +",开始抢购" + "|"; } } } jj1 = jj1.Substring(0, jj1.Length - 1); context.Response.Write(jj1); }