Chạy ❯
Nhận trang web của
riêng
bạn
×
Thay đổi định hướng
Lưu mã
Thay đổi chủ đề, Tối/Sáng
Đi tới Không gian
<!DOCTYPE html> <html> <body> <h2>Tạo danh sách thả xuống dựa trên dữ liệu JSON.</h2> <p id="demo"></p> <script> const dbParam = JSON.stringify( {bảng:"khách hàng",giới hạn:20}); const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { const myObj = JSON.parse(this.responseText); let text = "<select>" for (let x in myObj) { text += "<option>" + myObj[x].name + "</option>"; } text += "</select>" document.getElementById("demo").innerHTML = text; } xmlhttp.open("POST", "json_demo_html_table.php"); xmlhttp.setRequestHeader("Loại nội dung", "application/x-www-form-urlencoded"); xmlhttp.send("x=" + dbParam); </script> </body> </html>