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>Nhận dữ liệu JSON từ máy chủ PHP</h2> <p id="demo"></p> <script> const obj = { "limit":10 } ; const dbParam = JSON.stringify(obj); const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { myObj = JSON.parse(this.responseText); let text = "" for (let x in myObj) { text += myObj[x].name + "<br>"; } document.getElementById("demo").innerHTML = văn bản; }; xmlhttp.open("NHẬN", "json_demo_db.php?x=" + dbParam); xmlhttp.send(); </script> <p>Thử thay đổi thuộc tính "giới hạn" từ 10 thành 5.</p> </body> </html>