1.ajaxajax
$.ajax({ url: '/path/to/file', type: 'GET', dataType: 'json', data: {param1: 'value1'}, success: function (data){ //遍歷obj } })
2. 數據準備json
var data= { "status":1, "bkmsg":"\u6210\u529f", "bkdata":["\u5415\u5c1a\u5fd7","1387580400","\u6dfb\u52a0\u8bb0\u5f55"] };
// js的方法dom
3.for循環this
if (obj.status == 1) { for (var i = 0; i < obj.bkdata.length; i++) { console.log(obj.bkdata[i]); }; }else{ alert("數據有誤~"); };
4.for in 循環url
if (obj.status == 1) { for (var i = 0; i < obj.bkdata.length; i++) { console.log(obj.bkdata[i]); }; }else{ alert("數據有誤~"); };
// jq的each dom元素spa
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的$.eachcode
$.each( obj.bkdata, function(index,item){ console.log(item); });