function getData() {
    $.ajax({
        url: './json/third-level-address.json',
        type: 'get',
        async: false,
        success: function (data) {
            if (data == "error") {
                alert("系统错误");
                return;
            }
            dataJson = data;
        }
    });
    return dataJson;
}


function getCountry() {
    var data = getData();
    var options = "<option value='0'>--请选择--</option>";
    for (var i in data) {
        options += "<option value='" + data[i].code + "' selected>" + data[i].name + "</option>";
        $("#province").html(options);
    }
}

function getCity(countryCode) {
    var data = getData();
    $('#city').empty();
    var options = "<option value='0'>--请选择--</option>";
    for (var i in data) {
        for (let j = 0; j < data[i].children.length; j++) {
            if (countryCode && countryCode == data[i].code) {
                options += "<option value='" + data[i].children[j].code + "' selected>" + data[i].children[j].name + "</option>";
            }

        }
        $("#city").html(options);
    }

}

function getArea(cityCode) {
    var data = getData();
    var options = "<option value='0'>--请选择--</option>";
    for (var i in data) {
        for (let j = 0; j < data[i].children.length; j++) {
            for (let k = 0; k < data[i].children[j].children.length; k++) {
                if (cityCode && cityCode == data[i].children[j].code) {
                    options += "<option value='" + data[i].children[j].children[k].code + "' selected>" + data[i].children[j].children[k].name + "</option>";
                }
            }
        }
        $("#area").html(options);
    }

}