在.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以上!
新聞熱點
疑難解答