首页 > 扩展 > JSON > 正文

aspx后台传递Json到前台的两种接收方法推荐

2024-09-06 20:18:16
字体:
来源:转载
供稿:网友

第一种:前台接收

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 准备一个具备大小(宽高)的Dom --><div id="main" style="width:1000px;height:400px;"></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: []      }]    });    // 异步加载数据    $.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;        }        // 填入数据        myChart.setOption({          xAxis: {            data: varAxis          },          series: [{            //根据名字对应到相应的系列            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);。。。。。}            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表