One - One Code All

Blog Content

jquery ajax json 数据的遍历

前端相关 WEB   2015-01-15 21:09:32

jquery ajax json 数据的遍历

需求:进行ajax请求后,后台传递回来以下json数据

{  
    "data":[  
                {"id":"1","name":"选择A","value":"A"},  
                {"id":"2","name":"选择B","value":"B"},  
                {"id":"3","name":"选择C","value":"C"}  
            ]  
}

对上面的json数据类在jquery 的success 函数中解析

$.ajax({  
        type: "POST",  
        url: "xxx.do",  
        dataType : "json",  // 指定返回类型  
        data: {xxx:"yyy"},  // 传递到后台的参数  
        success: function(data)   
        {  
            $.each(data, function(index,values){   // 解析出data对应的Object数组  
                $.each(values,function(index2,value){   // 遍历Object数组 ,每个对象的值存放在value ,index2表示为第几个对象  
                    //  根据自己的逻辑进行数据的处理  
                    alert(value.name + "  " + value.value);  
                    //  TODO:  逻辑  
                });  
            });  
        },  
        error : function()  
        {  
            alert("系统出现问题");      
        }  
});



上一篇:jQuery修改标签的text显示内容或value值
下一篇:将后端返回的文件流转为图片路径直接展示图片

The minute you think of giving up, think of the reason why you held on so long.