您好,登錄后才能下訂單哦!
這期內(nèi)容當中小編將會給大家?guī)碛嘘P在aspx后臺傳遞的Json數(shù)據(jù)怎么在前臺接收,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
第一種:前臺接收
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="scripts/echarts.common.min.js"></script> <script src="scripts/jquery-1.10.2.min.js"></script> <script src="scripts/json2.js"></script> </head> <body> <form id="form1" runat="server"> <!-- 為 ECharts 準備一個具備大?。▽捀撸┑腄om --> <div id="main" > </div> <script type="text/javascript"> var varAxis; var varSeries; //var varRtcNO = $("#txtHid").val(); var varRtcNO = "35000002818"; var jdata; var myChart = echarts.init(document.getElementById('main')); // 顯示標題,圖例和空的坐標軸 myChart.setOption({ title: { text: '溫度曲線圖' }, tooltip: { trigger: 'axis', axisPointer: { animation: false }, formatter: function (params) { return params[0].name + '<br />溫度:' + params[0].value + '°C'; } }, legend: { data: ['溫度'] }, xAxis: { data: [] }, yAxis: { axisLabel: { formatter: '{value} °C' }, min: 18, max:30 }, series: [{ name: '溫度', type: 'line', smooth: true, data: [] }] }); // 異步加載數(shù)據(jù) $.ajax({ type: "post", url: "getrtchistorydata.ashx?rtcno=" + varRtcNO, dataType: "json", success: function (data) { var varReceiver = data; //var varReceiver = jQuery.parseJSON(data); var varAxis=new Array() ; var varSeries = new Array(varReceiver.Count[0].total); for (var i = 0; i < varReceiver.Count[0].total; i++) { varAxis.push(varReceiver.Rows[i].RecordTime); varSeries[i] = varReceiver.Rows[i].RoomTemp; } // 填入數(shù)據(jù) myChart.setOption({ xAxis: { data: varAxis }, series: [{ //根據(jù)名字對應到相應的系列 name: '溫度', data: varSeries }] }); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); </script> </form> </body> </html>
第二種:前臺接收
dataType: "text", success: function (data) { //var varReceiver = data; var varReceiver = jQuery.parseJSON(data); 。。。。。 }
兩者統(tǒng)一的后臺 一般處理程序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+ "}]";//用來記錄一共返回了幾條數(shù)據(jù)記錄 stbList = stbList + "}"; context.Response.Write(stbList.ToString()); } public bool IsReusable { get { return false; } } public void RetrunHistoryData() { } } }
上述就是小編為大家分享的在aspx后臺傳遞的Json數(shù)據(jù)怎么在前臺接收了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。