脚本异步时切记声明数据格式
function test(){ $.ajax({ type: "POST", url: "json.txt", data: '000', dataType:'json',//此项十分重要,切记! success: function(msg){ var data_text=""; $.each(msg.logistics_companies_get_response.logistics_companies.logistics_company, function(i,item){ data_text+="code:"+item.code+", id:"+item.id+", name:"+item.name+"<br/>";}) $("div").html(data_text); $("p").html('总共个数:'+msg.logistics_companies_get_response.logistics_companies.logistics_company.length);} }); } test();