C# JS 前后端互传数据

---恢复内容开始---

 

后端:

C# JS 前后端互传数据
 1 public void ProcessRequest(HttpContext context)
 2 {
 3 context.Response.ContentType = "text/plain";
 4 string IMEI = context.Request.QueryString["ID"];
 5 string currentDateTime = DateTime.Now.ToShortDateString();
 6 string cmd = "select TOP 20 温度,电池电压,电池电量,采集时间 from View_GPRS where 采集时间>‘" + currentDateTime + "‘ and 设备号 =‘" + IMEI + "‘ order by 采集时间 desc";
 7 // 访问数据库
 8 using (SqlDataReader reader = SqlHelper.ExcuteDataReader(cmd))
 9 {
10 if (reader.HasRows)
11 {
12 while (reader.Read())
13 {
14 
15 if (reader[0].ToString() == ""||reader[1].ToString()==""|| reader[2].ToString()==""|| reader[3].ToString()=="")
16 {
17 continue;
18 }
19 
20 //在第一个位置插入元素,相当于倒序排列,将元素从旧到新排序
21 energyInfo.Temp.Insert(0,Convert.ToDouble(reader[0]));//温度
22 energyInfo.BatteryVoltage.Insert(0,Convert.ToDouble(reader[1]));//电压
23 energyInfo.BatterySOC.Insert(0,Convert.ToDouble(reader[2]));//电量
24 DateTime colleTime = Convert.ToDateTime(reader[3].ToString()) ;
25 string sss = colleTime.ToString("T");
26 energyInfo.CollectionTime.Insert(0, colleTime.ToString("T"));//采集时间
27 
28 }
29 }
30 }
31 object JSONObj = JsonConvert.SerializeObject(energyInfo);
32 
33 //数据库内容转成json
34 context.Response.Write(JSONObj);
35 
36 }
View Code

 

前端:

 

   

 if (selectedLayer === getLayerByTitle(‘企业‘)) {
       console.info(‘点击餐车图层上的点,跳转页面到折线图‘);
      var IMEI = dic_values[‘IMEI‘];
      //跳转,将feature的属性数据传递到新页面
     //window.location.href = ‘Details.aspx?name=‘ + name;
      window.open(‘Details.aspx?name=‘ + IMEI);
}

  

//获取url中的参数 function getQueryParams() { var search = window.location.search; var params = {}; if (search != "") { search.slice(1).split("&").forEach( function (val) { var arr = val.split("="); params[arr[0]] = arr[1]; } ); } return params; } //获取url中的参数 var params = getQueryParams(); var query = decodeURI(params[‘name‘]); $.ajax({ type: "GET", url: ‘ Handler2.ashx?ID=‘ + query, contentType: "application/json", data: {}, success: function (res) { jsondata = JSON.parse(res); console.log(‘取到设备的温度,电压,电量数据‘); console.log(jsondata) option1.series[0].data = jsondata.Temp;//餐车温度 option1.xAxis[0].data = jsondata.CollectionTime; option2.series[0].data = jsondata.BatteryVoltage;//电池电压 option2.xAxis[0].data = jsondata.CollectionTime; option3.series[0].data = jsondata.BatterySOC;//电池电量 option3.xAxis[0].data = jsondata.CollectionTime;//采集时间 myChart1.setOption(option1); myChart2.setOption(option2); myChart3.setOption(option3); }, });

  

---恢复内容结束---

C# JS 前后端互传数据

上一篇:winfrom ComboBox


下一篇:1.在VMware下创建windows2008虚拟机