ajax对返回的json数据的处理

前端之家收集整理的这篇文章主要介绍了ajax对返回的json数据的处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

返回的json数据如下:

<span style="color: rgb(51,51,51); font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; line-height: 24px; background-color: rgb(245,245,245);">{"cityList":[{"create_date":"2013-09-04","cityID":"320200","modify_date":"2013-09-04","c_id":75,"father":"320000","city":"无锡市"},{"create_date":"2013-09-04","cityID":"320400","c_id":77,"city":"常州市"},"cityID":"320600","c_id":79,"city":"南通市"},"cityID":"320800","c_id":81,"city":"淮安市"},"cityID":"320900","c_id":82,"city":"盐城市"},"cityID":"321100","c_id":84,"city":"镇江市"},"cityID":"321300","c_id":86,"city":"宿迁市"},"cityID":"320100","c_id":74,"city":"南京市"},"cityID":"320300","c_id":76,"city":"徐州市"},"cityID":"320500","c_id":78,"city":"苏州市"},"cityID":"320700","c_id":80,"city":"连云港市"},"cityID":"321000","c_id":83,"city":"扬州市"},"cityID":"321200","c_id":85,"city":"泰州市"}]}</span>
===================华丽的分割线=====================================
$.ajax({
    url:"city",type:"POST",data:"father="+father,dataType: "json",success:function(jsonList){
        var html="";
        for(var i=0;i<=jsonList.cityList.length-1;i++){
            html+="城市"+jsonList.cityList[i].city+",c_id="+jsonList.cityList[i].c_id+"\n";
        }
        alert(html);
    }
    });
重点看两句代码
dataType:"json" 这样设置以后返回的类型就是json对象了,不用转换,就可以直接用了! 原文链接:https://www.f2er.com/ajax/164275.html

猜你在找的Ajax相关文章