\n```\n\n### Classic version with XMLHttpRequest\n```js\nconst xhr = new XMLHttpRequest();\nxhr.open('GET', 'data.php?id=1', true); // true = asynchronous\nxhr.onreadystatechange = function () {\n if (xhr.readyState === 4 && xhr.status === 200) {\n document.getElementById('result').innerHTML = xhr.responseText;\n }\n};\nxhr.send();\n```\n\n## How the page is updated with the response\n1. An event (click, keypress, timer) triggers a JavaScript function.\n2. JavaScript sends an **asynchronous request** to the server (`fetch`/`XMLHttpRequest`).\n3. The server processes it and returns data (JSON, XML, or HTML fragment).\n4. A callback (or `await`) receives the response once it arrives; the page stays usable meanwhile.\n5. JavaScript **parses** the data (`res.json()`) and modifies the **DOM** (`textContent`, `innerHTML`, `appendChild`) to show it.\n\n**Note:** `innerHTML` with untrusted data risks XSS, so prefer `textContent` or sanitize the data."}}}Back to the 2024 paper
Similar questions
Web TechnologyDescribe the important features of JavaScript and explain its role in developing interactive web pages with a suitable example.20267mWeb TechnologyWrite short notes on the following : (a) HTML commands (b) DHTML dragging and drooping (c) AWT (d) JDBC202014mWeb TechnologyWrite short notes on any two of the following: (a) AWT (b) Exception Handling (c) DHTML and HTML (d) API201914mWeb TechnologyHow can CSS be used to display a XML document? Illustrate with an example.20237m
PreviousDescribe how to handle form data in PHP. Explain the creation of an HTML form, focusing on the method and action attributes. Discuss retrieving data using the GET and POST methods, and provide a code example demonstrating the form submission process.NextWhat are the different e-business models? Compare B2B, B2C, C2C, and C2B models with examples.
Free AppAndroid App
Coursify Android App
Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.