讲解asp.net中Jquery解析json数据格式相关知识

发布时间:2020-06-28 11:36:11 作者:jgsa
来源:网络 阅读:304

aspx前台页面代码如下:
 
    <script language="javascript" type="text/javascript">
 
    function  TestAjax(){
 
    $.ajax({
 
    url: "/", //ajax请求的路径     dataType: "json",
 
    data: "id=150"+"&r=" + Math.random(), //请求的参数
 
    type: "post",
 
    success: function (data) {
 
    alert(data.name); //弹出data对象的name属性值
 
    }
 
    });
 
    }
 
    </script>
 
    后台。cs文件如下:
 
    protected void Page_Load(object sender, EventArgs e)
 
    {
 
    if (!IsPostBack)
 
    {
 
    if (Request.QueryString["id"] != null)
 
    {
 
    string id = Request.QueryString["id"].ToString();
 
    Context.Response.ContentType = "text/plain";
 
    //构建的json数据(只有一条数据可以直接用{},如果有多条数据需要用[],前台用索引访问) 例如jsonstr = "[{\"pricelist\":\"" + temm + "\",\"jianye\":\"" + jianye + "\",\"sigleprice\":\"" + oneytempprice + "\",\"jianyetotalprice\":\"" + jianyetotalprice + "\"}]";
 
    string data = "{\"id\":\"" + id + "\",\"name\":\"测试内容 \",\"sigleprice\":\"120.0 \",\"jianyetotalprice\":\"123.2\"}";
 
    Context.Response.Write(data);
 
    Context.Response.End();
 
    }
 
    }
 
    }
 

推荐阅读:
  1. session相关知识
  2. HTML相关知识

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ajax javascript 知识

上一篇:大数据应该学python还是java呢

下一篇:java中的封装怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》