API lấy thông tin 34 Tỉnh Thành, Phường Xã Mới Của Việt Nam
Cập nhật mới nhất: 01/08/2015
Demo code:
Cấu trúc API:
- Lấy Tỉnh Thành: https://esgoo.net/api-tinhthanh-new/{A}/{B}.htm
- Biến {A}: giá trị 1
- Biến {B}: giá trị là 0
- Links demo dữ liệu: https://esgoo.net/api-tinhthanh-new/1/0.htm
- Lấy Phường Xã: https://esgoo.net/api-tinhthanh-new/{A}/{B}.htm
- Biến {A}: giá trị 2
- Biến {B}: giá trị là id tỉnh thành
- Links demo dữ liệu: https://esgoo.net/api-tinhthanh-new/2/14480.htm
- Lấy Đầy Đủ: https://esgoo.net/api-tinhthanh-new/{A}/{B}.htm
- Biến {A}: giá trị 4
- Biến {B}: giá trị là 0
- Links demo dữ liệu: https://esgoo.net/api-tinhthanh-new/4/0.htm
- Lấy Tên Phường, Quận, Tỉnh: https://esgoo.net/api-tinhthanh-new/{A}/{B}.htm
- Biến {A}: giá trị 5
- Biến {B}: giá trị là id cần lấy
- Links demo dữ liệu: https://esgoo.net/api-tinhthanh-new/5/14480.htm
Code mẫu HTML, JQUERY dùng getJSON:
<script src="https://esgoo.net/scripts/jquery.js"></script>
<style type="text/css">
.css_select_div{ text-align: center;}
.css_select{ display: inline-table; width: 25%; padding: 5px; margin: 5px 2%; border: solid 1px #686868; border-radius: 5px;}
</style>
<script>
$(document).ready(function() {
//Lấy tỉnh thành
$.getJSON('https://esgoo.net/api-tinhthanh-new/1/0.htm',function(data_tinh){
if(data_tinh.error==0){
$.each(data_tinh.data, function (key_tinh,val_tinh) {
$("#tinh").append('<option value="'+val_tinh.id+'">'+val_tinh.full_name+'</option>');
});
$("#tinh").change(function(e){
var idtinh=$(this).val();
//Lấy phường xã
$.getJSON('https://esgoo.net/api-tinhthanh-new/2/'+idtinh+'.htm',function(data_quan){
if(data_quan.error==0){
$("#quan").html('<option value="0">Phường Xã</option>');
$.each(data_quan.data, function (key_quan,val_quan) {
$("#quan").append('<option value="'+val_quan.id+'">'+val_quan.full_name+'</option>');
});
}
});
});
}
});
});
</script>
<div class="css_select_div">
<select class="css_select" id="tinh" name="tinh" title="Chọn Tỉnh Thành">
<option value="0">Tỉnh Thành</option>
</select>
<select class="css_select" id="quan" name="quan" title="Chọn Phường Xã">
<option value="0">Phường Xã</option>
</select>
</div>