最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
echarts+ashx+json获取数据展示例子
时间:2016-06-01 编辑:简简单单 来源:一聚教程网
ashx是net提供的一般处理程序,比aspx返回的数据量少很多,适合做接口。
html代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="echart2.aspx.cs" Inherits="RTC.echart2" %>
js代码:
url: "getrtchistorydata.ashx?rtcno=" + varRtcNO,就是服务端接收参数和返回数据的方法。
服务端方法:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace RTC
{
///
/// getrtchistorydata 的摘要说明
///
public class getrtchistorydata : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string strRTCNo = context.Request.QueryString["rtcno"].ToString();
SqlConnection con = new SqlConnection("server=192.168.0.222;uid=sa;pwd=hiwits;database=CeShi_QingDao;Max Pool Size=2048;");
SqlCommand cmd = new SqlCommand("select RtcNO,RoomTemp,InstallPlace,convert(varchar,RecordTime,120) as RecordTime,systime from RTCHistory where RtcNO='" + strRTCNo + "' order by InstallPlace,RecordTime", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
string stbList = "";
stbList = "{\"Rows\":[";
foreach (DataRow dr in ds.Tables[0].Rows)
{
stbList = stbList + "{ \"RecordTime\":\"" + dr[3].ToString() + "\",";
stbList = stbList + " \"RoomTemp\":\"" + dr[1].ToString() + "\"},";
}
stbList = stbList.Substring(0, stbList.Length - 1);//去掉最后的一个逗号
stbList = stbList + "],";
stbList = stbList + "\"Count\":[{\"total\":" + ds.Tables[0].Rows .Count+ "}]";//用来记录一共返回了几条数据记录
stbList = stbList + "}";
context.htm = htm&(stbList.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
public void RetrunHistoryData()
{
}
}
}
其中,ajax的参数: dataType: "text",也可以是 dataType: "json",服务端在返回的时候,如果是json就序列化一下。请看参考。
在ajax成功后,反序列化一下就行。var varReceiver = jQuery.parseJSON(data);
相关文章
- HTML简单购物数量小程序代码展示 10-31
- html canvas实现弹幕功能 10-31
- HTML中空格表示的意义 10-31
- html area标签解读 10-31
- html使用表单标签实现注册页面代码展示 10-31
- 使用HTML截图并保存为本地图片的代码展示 10-31