layer .net中使用

在.net中使用layer得用ajax来请求一般处理程序来得到想要的json数据,直接上代码

html:

<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>layer</title>
    <script src="layer/jquery-1.9.1.min.js"></script>
    <script src="layer/layer.min.js"></script>
    <script src="layer/extend/layer.ext.js"></script>
</head>
<body>
    <div style="width: 100%; height: 100%; text-align: center;">
        <div id="testMaxmin" style="width: 100px; height: 100px; background-color: #808080"></div>
        <script>
            $('#testMaxmin').on('click', function () {
                $.layer({
                    type: 2,
                    maxmin: true,
                    title: '网络电视',
                    area: ['580px', '350px'],
                    iframe: {
                        src: 'http://t.cn/zW9SbfS'
                    }
                })
            });
        </script>
        <div id="testPhotos" style="width: 100px; height: 100px; background-color: #ff6a00">
            </div>
        <script>
            var photos;
            $('#testPhotos').on('click', function () {
                //判断是否已经请求过相册,已请求过,则直接读取缓存数据
                if (photos) {
                    layer.photos({
                        html: '', //如果此处传入html值,则右侧区域会显示,不传则不显示
                        json: photos
                    });
                } else {
                    layer.load();
                    $.ajax({
                        url: "handler.ashx",
                        type: "post"
                    }).done(function (da) {
                        json = JSON.parse(da);
                        photos = json;
                        layer.photos({
                            html: '', //如果此处传入html值,则右侧区域会显示,不传则不显示
                            json: json
                        });
                        layer.closeLoad()
                    });
                }
            });
        </script>
    </div>
</body>

 handler.ashx

public void ProcessRequest(HttpContext context)
    {
        JavaScriptSerializer jss = new JavaScriptSerializer();
        context.Response.ContentType = "text/plain";
        string data = "{\"status\": 1,\"msg\": \"\",\"title\": \"hahahaha\",\"id\": 8,\"start\": 0,\"data\": [{\"name\": \"qwe\",\"pid\": 109,\"src\": \"../images/1.jpg\",\"thumb\": \"\",\"area\": [638,851]},{\"name\": \"weq\",\"pid\": 110,\"src\": \"../images/2.jpg\",\"thumb\": \"\",\"area\": [638,851]}]}";

        context.Response.Write(data);
    }

 图片地址什么的可以自己改,一定注意要引用js,jquery要1.8以上!

 

转载于:https://www.cnblogs.com/LiuLiangXuan/p/4214696.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值