jquery 获取json数据实现代码


复制代码 代码如下:

//栏目
//发送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("加载成功");
// })

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3