okay send me proper ajax table code
- User
okay send me proper ajax table code
Assistant
Here's a simple AJAX table implementation:
<!DOCTYPE html> <html> <head> <title>AJAX Table Example</title> <style> table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } tr:nth-child(even) { background-color: #f9f9f9; } </style> </head> <body> <h2>AJAX Data Table</h2> <button onclick="loadData()">Load Data</button> <div id="tableContainer"> <table id="dataTable"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Email</th> </tr> </thead> <tbody id="tableBody"> <!-- Data will be loaded here --> </tbody> </table> </div> <script> function loadData() { const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { const data = JSON.parse(this.responseText); populateTable(data); } }; xhr.open("GET", "https://jsonplaceholder.typicode.com/users", true); xhr.send(); } function populateTable(data) { const tableBody = document.getElementById("tableBody"); tableBody.innerHTML = ""; data.forEach(item => { const row = document.createElement("tr"); const idCell = document.createElement("td"); idCell.textContent = item.id; row.appendChild(idCell); const nameCell = document.createElement("td"); nameCell.textContent = item.name; row.appendChild(nameCell); const emailCell = document.createElement("td"); emailCell.textContent = item.email; row.appendChild(emailCell); tableBody.appendChild(row); }); } </script> </body> </html>Would you like me to explain or break down this code?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.