第一种:前台接收
dataType: "json", success: function (data) { var varReceiver = data; }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="echart2.aspx.cs" Inherits="RTC.echart2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title> </title> <!-- 引入 ECharts 文件 --> <script src="/UploadFiles/2021-04-02/echarts.common.min.js">第二种:前台接收
dataType: "text", success: function (data) { //var varReceiver = data; var varReceiver = jQuery.parseJSON(data); 。。。。。 }两者统一的后台 一般处理程序ashx:
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; namespace RTC { /// <summary> /// getrtchistorydata 的摘要说明 /// </summary> 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.Response.Write(stbList.ToString()); } public bool IsReusable { get { return false; } } public void RetrunHistoryData() { } } }以上这篇aspx后台传递Json到前台的两种接收方法推荐就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
aspx,Json
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“aspx后台传递Json到前台的两种接收方法推荐”评论...