1.ajax
$.ajax({ url: '/path/to/file', type: 'GET', dataType: 'json', data: {param1: 'value1'}, success: function (data){ //遍历obj } })
2. 数据准备
var data= { "status":1, "bkmsg":"u6210u529f", "bkdata":["u5415u5c1au5fd7","1387580400","u6dfbu52a0u8bb0u5f55"] };
// js的方法
3.for循环
if (obj.status == 1) { for (var i = 0; i < obj.bkdata.length; i++) { console.log(obj.bkdata[i]); }; }else{ alert("数据有误~"); };
4.for in 循环
if (obj.status == 1) { for (var i = 0; i < obj.bkdata.length; i++) { console.log(obj.bkdata[i]); }; }else{ alert("数据有误~"); };
// jq的each dom元素
if (obj.status == 1) { $(obj.bkdata).each(function(index,item){ //index指下标 //item指代对应元素内容 //this指代每一个元素对象 //console.log(obj.bkdata[index]); console.log(item); //console.log($(this)); }); }else{ alert("数据有误~"); };
jq的$.each
$.each( obj.bkdata, function(index,item){ console.log(item); });