Spaces:
Running
Running
Update index.html
Browse files- index.html +12 -7
index.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
<html lang="vi">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<title>Tra cứu Đơn vị Hành chính -
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 7 |
<!-- Bootstrap 5 CDN -->
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
@@ -24,7 +24,7 @@
|
|
| 24 |
</head>
|
| 25 |
<body class="bg-light">
|
| 26 |
<div class="container py-5">
|
| 27 |
-
<h2 class="mb-4 text-primary">🔎 Tra cứu Đơn vị Hành chính
|
| 28 |
<div class="card shadow p-4 mb-4">
|
| 29 |
<form id="searchForm" autocomplete="off">
|
| 30 |
<div class="row mb-3">
|
|
@@ -59,7 +59,12 @@
|
|
| 59 |
<!-- Choices.js: Tìm kiếm nhanh select -->
|
| 60 |
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
|
| 61 |
<script>
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
const provinceSel = document.getElementById("province");
|
| 64 |
const districtSel = document.getElementById("district");
|
| 65 |
const wardSel = document.getElementById("ward");
|
|
@@ -74,7 +79,7 @@ let districtChoices = new Choices(districtSel, { searchEnabled: true, itemSelect
|
|
| 74 |
let wardChoices = new Choices(wardSel, { searchEnabled: true, itemSelectText: '', shouldSort: false });
|
| 75 |
|
| 76 |
async function loadProvinces() {
|
| 77 |
-
let res = await fetch(apiBase + '/provinces');
|
| 78 |
let data = await res.json();
|
| 79 |
let opts = data.map(p => ({ value: p, label: p }));
|
| 80 |
provinceChoices.setChoices([{ value: '', label: '-- Chọn/Tìm tỉnh/thành phố --', selected: true, disabled: true }, ...opts], 'value', 'label', true);
|
|
@@ -85,7 +90,7 @@ provinceSel.addEventListener("change", async function() {
|
|
| 85 |
districtChoices.setChoices([{ value: '', label: '-- Chọn/Tìm quận/huyện --', selected: true, disabled: true }], 'value', 'label', true);
|
| 86 |
wardChoices.setChoices([{ value: '', label: '-- Chọn/Tìm phường/xã --', selected: true, disabled: true }], 'value', 'label', true);
|
| 87 |
if (!this.value) return;
|
| 88 |
-
let res = await fetch(apiBase + '/districts?province=' + encodeURIComponent(this.value));
|
| 89 |
let data = await res.json();
|
| 90 |
let opts = data.map(d => ({ value: d, label: d }));
|
| 91 |
districtChoices.setChoices([{ value: '', label: '-- Chọn/Tìm quận/huyện --', selected: true, disabled: true }, ...opts], 'value', 'label', true);
|
|
@@ -95,7 +100,7 @@ districtSel.addEventListener("change", async function() {
|
|
| 95 |
wardChoices.clearStore();
|
| 96 |
wardChoices.setChoices([{ value: '', label: '-- Chọn/Tìm phường/xã --', selected: true, disabled: true }], 'value', 'label', true);
|
| 97 |
if (!this.value || !provinceSel.value) return;
|
| 98 |
-
let res = await fetch(apiBase + '/wards?province=' + encodeURIComponent(provinceSel.value) + '&district=' + encodeURIComponent(this.value));
|
| 99 |
let data = await res.json();
|
| 100 |
let opts = data.map(w => ({ value: w, label: w }));
|
| 101 |
wardChoices.setChoices([{ value: '', label: '-- Chọn/Tìm phường/xã --', selected: true, disabled: true }, ...opts], 'value', 'label', true);
|
|
@@ -110,7 +115,7 @@ searchForm.addEventListener("submit", async function(e) {
|
|
| 110 |
if (provinceSel.value) params.push('oldProvince=' + encodeURIComponent(provinceSel.value));
|
| 111 |
if (districtSel.value) params.push('oldDistrict=' + encodeURIComponent(districtSel.value));
|
| 112 |
if (wardSel.value) params.push('oldWard=' + encodeURIComponent(wardSel.value));
|
| 113 |
-
let url = apiBase + '/search?' + params.join('&');
|
| 114 |
try {
|
| 115 |
let res = await fetch(url);
|
| 116 |
let data = await res.json();
|
|
|
|
| 2 |
<html lang="vi">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<title>Tra cứu Đơn vị Hành chính - Sáp nhập 3321</title>
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 7 |
<!-- Bootstrap 5 CDN -->
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
| 24 |
</head>
|
| 25 |
<body class="bg-light">
|
| 26 |
<div class="container py-5">
|
| 27 |
+
<h2 class="mb-4 text-primary">🔎 Tra cứu Đơn vị Hành chính Sáp nhập 3321</h2>
|
| 28 |
<div class="card shadow p-4 mb-4">
|
| 29 |
<form id="searchForm" autocomplete="off">
|
| 30 |
<div class="row mb-3">
|
|
|
|
| 59 |
<!-- Choices.js: Tìm kiếm nhanh select -->
|
| 60 |
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
|
| 61 |
<script>
|
| 62 |
+
// Dùng corsproxy.io để vượt lỗi CORS trên Hugging Face
|
| 63 |
+
function apiUrl(path) {
|
| 64 |
+
// Sử dụng dạng encodeURL để tránh lỗi CORS
|
| 65 |
+
return 'https://corsproxy.io/?' + encodeURIComponent('https://api.luat.ai' + path);
|
| 66 |
+
}
|
| 67 |
+
const apiBase = "/administrative";
|
| 68 |
const provinceSel = document.getElementById("province");
|
| 69 |
const districtSel = document.getElementById("district");
|
| 70 |
const wardSel = document.getElementById("ward");
|
|
|
|
| 79 |
let wardChoices = new Choices(wardSel, { searchEnabled: true, itemSelectText: '', shouldSort: false });
|
| 80 |
|
| 81 |
async function loadProvinces() {
|
| 82 |
+
let res = await fetch(apiUrl(apiBase + '/provinces'));
|
| 83 |
let data = await res.json();
|
| 84 |
let opts = data.map(p => ({ value: p, label: p }));
|
| 85 |
provinceChoices.setChoices([{ value: '', label: '-- Chọn/Tìm tỉnh/thành phố --', selected: true, disabled: true }, ...opts], 'value', 'label', true);
|
|
|
|
| 90 |
districtChoices.setChoices([{ value: '', label: '-- Chọn/Tìm quận/huyện --', selected: true, disabled: true }], 'value', 'label', true);
|
| 91 |
wardChoices.setChoices([{ value: '', label: '-- Chọn/Tìm phường/xã --', selected: true, disabled: true }], 'value', 'label', true);
|
| 92 |
if (!this.value) return;
|
| 93 |
+
let res = await fetch(apiUrl(apiBase + '/districts?province=' + encodeURIComponent(this.value)));
|
| 94 |
let data = await res.json();
|
| 95 |
let opts = data.map(d => ({ value: d, label: d }));
|
| 96 |
districtChoices.setChoices([{ value: '', label: '-- Chọn/Tìm quận/huyện --', selected: true, disabled: true }, ...opts], 'value', 'label', true);
|
|
|
|
| 100 |
wardChoices.clearStore();
|
| 101 |
wardChoices.setChoices([{ value: '', label: '-- Chọn/Tìm phường/xã --', selected: true, disabled: true }], 'value', 'label', true);
|
| 102 |
if (!this.value || !provinceSel.value) return;
|
| 103 |
+
let res = await fetch(apiUrl(apiBase + '/wards?province=' + encodeURIComponent(provinceSel.value) + '&district=' + encodeURIComponent(this.value)));
|
| 104 |
let data = await res.json();
|
| 105 |
let opts = data.map(w => ({ value: w, label: w }));
|
| 106 |
wardChoices.setChoices([{ value: '', label: '-- Chọn/Tìm phường/xã --', selected: true, disabled: true }, ...opts], 'value', 'label', true);
|
|
|
|
| 115 |
if (provinceSel.value) params.push('oldProvince=' + encodeURIComponent(provinceSel.value));
|
| 116 |
if (districtSel.value) params.push('oldDistrict=' + encodeURIComponent(districtSel.value));
|
| 117 |
if (wardSel.value) params.push('oldWard=' + encodeURIComponent(wardSel.value));
|
| 118 |
+
let url = apiUrl(apiBase + '/search?' + params.join('&'));
|
| 119 |
try {
|
| 120 |
let res = await fetch(url);
|
| 121 |
let data = await res.json();
|