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 dữ liệu JSON.</h2> <p id="demo"></p> <script> const dbParam = JSON.stringify({table :"khách hàng",giới hạn:20}); const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { const myObj = JSON.parse(this.responseText); let text = "<table border='1'>" for (let 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"); xmlhttp.setRequestHeader("Loại nội dung", "application/x-www-form-urlencoded"); xmlhttp.send("x=" + dbParam); </script> </body> </html>