栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

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

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

第一种:前台接收

dataType: "json",
 success: function (data)
 {
	var varReceiver = data;
 }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="echart2.aspx.cs" Inherits="RTC.echart2" %>






   
  
  
  
  




第二种:前台接收

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
{
  /// 
  /// 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.Response.Write(stbList.ToString());
    }

    public bool IsReusable
    {
      get
      {
 return false;
      }
    }

    public void RetrunHistoryData()
    {


    }
  }
}

以上这篇aspx后台传递Json到前台的两种接收方法推荐就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/56320.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号