jquery 获取json数据实现代码
2009-04-27 00:00
796 查看
//栏目 //发送ajax请求 $.getJSON( "../../../Templet/GetInfoHandler.ashx", //产生JSON数据的服务端页面 {id: "0", sid: "1;2;3", rid: Math.round(Math.random() * 10) }, //向服务器发出的查询字符串 //对返回的JSON数据进行处理 function(json) { //循环取json中的数据,并呈现在列表中 $("#column_0_1").empty(); var colstr = '<h2><span><a href="#" href="#">更多>></a></span>热门招聘</h2><ul>'; $.each(json, function(i) { //alert(json[i].news_id); colstr = colstr + '<li><a href="http://www.ishixi.com/news/html/' + json[i].new_file_name + '" href="http://www.ishixi.com/news/html/' + json[i].new_file_name + '">' + json[i].news_title + '</a></li>'; }) colstr = colstr + '</ul>'; $("#column_0_1").html(colstr); alert("加载成功"); // })
用Litjson生成json数据的C#程序:
//栏目 //发送ajax请求 $.getJSON( "../../../Templet/GetInfoHandler.ashx", //产生JSON数据的服务端页面 {id: "0", sid: "1;2;3", rid: Math.round(Math.random() * 10) }, //向服务器发出的查询字符串 //对返回的JSON数据进行处理 function(json) { //循环取json中的数据,并呈现在列表中 $("#column_0_1").empty(); var colstr = '<h2><span><a href="#" href="#">更多>></a></span>热门招聘</h2><ul>'; $.each(json, function(i) { //alert(json[i].news_id); colstr = colstr + '<li><a href="http://www.ishixi.com/news/html/' + json[i].new_file_name + '" href="http://www.ishixi.com/news/html/' + json[i].new_file_name + '">' + json[i].news_title + '</a></li>'; }) colstr = colstr + '</ul>'; $("#column_0_1").html(colstr); alert("加载成功"); // })
jquery通过json获取数据
<script type="text/javascript"> $(document).ready(function () { getScatalog("paidang", "M06"); }); function getScatalog(selectid,BaseCode) { if (BaseCode != "") { $.ajax({ url: "ajax/getCatalogByBasecode.aspx", data: "code=" + encodeURI(BaseCode), cache: false, datatype: "html", success: function (context) { fillselect(selectid, context); } }); } else { return "Error"; } } function fillselect(selectid, context) { var listitem=new Array(); listitem = eval(context); for (var i = 0; i < listitem.length; i++) { $("#" + selectid).append("<option value='" + listitem[i]["code"] + "'>" + listitem[i]["name"] + "</option>"); //为Select追加一个Option(下拉项) } } </script>
html代码:
<select id="paidang" class="selectstyle" name="paidang"> <option value="" selected>==请选择==</option> </select>
Ajax:
新建一个.aspx页面删除.aspx页面里的html代码删除,在.aspx.cs里添加如下代码
string rq_basecode=null; rq_basecode = Request.QueryString["code"]; if (string.IsNullOrWhiteSpace(rq_basecode)) { Response.Write("Error"); Response.End(); } BLLCataLog bll_info = new BLLCataLog(); List<Scatalog> lt_info = new List<Scatalog>(); lt_info = bll_info.GetCatalog(rq_basecode,""); //Response.Write(rq_basecode); if (lt_info.Count > 0) { Response.Write(JsonHelper.ToJson(lt_info)); } else { Response.Write("Null"); }
BLL层的数据:
public List<M2Model.Scatalog> GetCatalog(string code, string refcode) { DALCataLog dalcatalog6 = new M2SharpDAL.DALCataLog(); return dalcatalog6.GetCatalog(code, refcode); }
相关文章推荐
- JQuery用$.ajax或$.getJSON跨域获取JSON数据的实现代码
- JQuery用$.ajax或$.getJSON跨域获取JSON数据的实现代码
- JQuery 获取json数据$.getJSON方法的实例代码
- android客户端从服务器端获取json数据并解析的实现代码
- android客户端从服务器端获取json数据并解析的实现代码
- jquery的ajax和getJson跨域获取json数据的实现方法
- jQuery中使用Ajax获取JSON格式数据示例代码
- android客户端从服务器端获取json数据并解析的实现代码
- 一个简单的Android客户端从服务器端获取json数据并解析的实现代码
- jQuery中使用Ajax获取JSON格式数据示例代码
- android客户端从服务器端获取json数据并解析的实现代码
- jQuery实现异步获取json数据的2种方式
- Android 客户端从服务端获取json数据并解析的实现代码
- jQuery前台数据获取实现代码
- 以jquery插件形式获取json数据实现级联
- jquery的ajax和getJson跨域获取json数据的实现方法
- jquery的ajax和getJson跨域获取json数据的实现方法
- JQuery 获取json数据$.getJSON方法的实例代码
- Android客户端从服务器端获取json数据并解析的实现代码