jquery json

来源:互联网 发布:阿里云 弹性ip bgp带宽 编辑:程序博客网 时间:2024/06/06 05:03
发起请求 
function testClick() { 
//alert('开始测试json'); 
$.ajax({ url:'Default.aspx', //后台处理程序 
type:'get', //数据发送方式 
dataType:'json', //接受数据格式 
data:{"act":"test"},//要传递的数据 
success:update_page //回传函数(这里是函数名) 
}); 


返回数据 {'totalCount':7, 'root':[ {'gcIndex':'1','Match':'australia','Message':'3|Error: View Details, please refer to the log file'}, {'gcIndex':'2','Match':'canada2','Message':'1|last No.519754'}, {'gcIndex':'3','Match':'canada','Message':'1|last No.1164047'}, {'gcIndex':'4','Match':'eklub','Message':'1|last No.298742'}, {'gcIndex':'5','Match':'keno8','Message':'1|last No.333185'}, {'gcIndex':'6','Match':'maltco','Message':'1|last No.317093'}, {'gcIndex':'7','Match':'maryland','Message':'2|Warning: View Details, please refer to the log file'} ] } 

解析 
function update_page(json) { 
$("#test").html(''); 
$("#test").append(Year_Month()+" " +Date_of_Today()+" " +Day_of_Today()+" " + CurentTime() +""); 
var retCnt = json.totalCount; 
var info = json.root; 
for(var i = 0;retCnt >0 && i < retCnt; i++)

$("#test").append("index:"+info[i].gcIndex+" Match:"+info[i].Match+" Message:"+info[i].Message +""); 

}