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 bảng dựa trên giá trị của menu thả xuống.</h2> <select id="myselect" onchange="change_myselect(this.value)"> < option value="">Chọn một tùy chọn:</option> <option value="customers">Khách hàng</option> <option value="products">Sản phẩm</option> <option value="suppliers">Nhà cung cấp< /option> </select> <p id="demo"></p> <script> function thay đổi_myselect(sel) { const dbParam = JSON.stringify({table:sel,limit:20}); const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { myObj = JSON.parse(this.responseText); text = "<table border='1'>" for (x in myObj) { text += "<tr><td>" + myObj[x].name + "</td></tr>"; } text += "</table>" document.getElementById("demo").innerHTML = text; } xmlhttp.open("POST", "json_demo_html_table.php", true); xmlhttp.setRequestHeader("Loại nội dung", "application/x-www-form-urlencoded"); xmlhttp.send("x=" + dbParam); } </script> </body> </html>