jsonp 监控简陋代码

  url: window.location.href

 Agent: navigator.userAgent

 

var tkInfo = {                   

   VisitUrl: window.location.href,          

   UserAgent: Visit.Agent,            

   SolutionCatalogId: Visit.SolId        

}

      $.ajax({          

   url: _urlBase + "/Track/AddTrackInfo",           

  data: { jsonData: JSON.stringify(tkInfo) },       

      type: 'get',            

jsonp: "jsonpcallback",            

success: function (data) {               

  console.log(data);            

}        

})

 using (MSDBcontext db = new MSDBcontext())
                {
                    string result = String.Empty;
                    //服务端获取IP地址
                    result = HttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    if (string.IsNullOrEmpty(result))
                    {
                        result = HttpContext.Request.ServerVariables["REMOTE_ADDR"];
                    }
                    if (string.IsNullOrEmpty(result))
                    {
                        result = HttpContext.Request.UserHostAddress;
                    }
                   
                    var tkInfo = new TrackInfo
                    {
                        UserId = trackInfo.UserId,
                        FromId = Guid.Parse(trackInfo.FromId),
                        FromUserId = trackInfo.FromUserId,
                        VisitorName = trackInfo.VisitorName,
                        VisitUrl = trackInfo.VisitUrl,
                        UserAgent = trackInfo.UserAgent,
                        VisitorIP = Request.UserHostName,

      }

return JavaScript(string.Format("{0}({1});", jsonpcallback, Newtonsoft.Json.JsonConvert.SerializeObject(jsonResult)));

//自增

db.Database.ExecuteSqlCommand("UPDATE TrackSta SET ShareCount=ShareCount+1 WHERE  Id = {0};", tStaInfo.Id);

 string str="select YEAR(CreateTime) as Y,month(CreateTime) as M,day(CreateTime) as D,datepart(Hour,createtime) as H, COUNT(*) as C,sum(case IsPay when 0 then 1  when 1 then 0 end ) as 'UnPay', sum(case IsPay when 1 then 1 when 0 then 0  end) as 'Pay' from orders where YEAR(CreateTime)='2015' group by YEAR(CreateTime),month(CreateTime),day(CreateTime), datepart(Hour,createtime)";
               var v =db.Database.SqlQuery(typeof(OrderChart), str, "");

 

3.json 格式 对应

  $.ajax({
        url: _BaseUrl + '/Video/GetLoadVideoData',
        type: 'post',
        datatype: 'json',
        data: {},
        success: function (data) {
            if (data != null) {
                //常规了解
                if (data.Data.RoutineDataList.length > 0) {

                 }

              }}

   }

 

  public ActionResult GetLoadVideoData(string type)        

  {            

     AjaxResult<LoadVideoData> result = new AjaxResult<LoadVideoData>           

     {                

       Status = -1,                 Message = "获取失败。",                

      Data = new LoadVideoData                

     {                     CaseDataList = null,                     ServiceDataList = null,                     RoutineDataList = null,                     TrainDataList = null                 }             };             using (AzureWeChatDbContext context = new AzureWeChatDbContext())             {                 var routineDataList = context.Database.SqlQuery<VisitDataListModel>("exec GetRoutineDataList").ToList();                 var serviceDataList = context.Database.SqlQuery<VisitDataListModel>("exec GetServiceDataList").ToList();                 var caseDataList = context.Database.SqlQuery<VisitDataListModel>("exec GetCaseDataList").ToList();                 var trainDataList = context.Database.SqlQuery<VisitDataListModel>("exec GetTrainDataList").ToList();                 //var LecturerDataList = context.Database.SqlQuery<VisitDataListModel>("exec GetLecturerDataList").ToList();

                result.Data.CaseDataList = caseDataList;                 result.Data.ServiceDataList = serviceDataList;                 result.Data.RoutineDataList = routineDataList;                 result.Data.TrainDataList = trainDataList;                 result.Status = 1;                 result.Message = "获取成功";             }             JsonResult jsonData = new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };             return jsonData;         }

 

posted @ 2016-05-19 17:07  李寒星  阅读(211)  评论(0编辑  收藏  举报