\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 and Internet TechnologyExplain the use of XML and the XMLHttpRequest object in implementing AJAX applications with a suitable example.20267mWeb and Internet TechnologyDiscuss the use of AJAX for creating dynamic HTML pages and highlight the role of CSS and XML in AJAX applications.20267mWeb and Internet TechnologyExplain the XMLHttpRequest object and describe its request and response objects with a suitable example.20267mWeb and Internet TechnologyA web page retrieves updated XML data and modifies only a table on the page. The browser does not reload the entire HTML document. Which property of AJAX is being demonstrated? (i) Asynchronous communication and partial page update (ii) Static document rendering (iii) XML validation (iv) Client-side compilation20262m
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.
Official AppAndroid App
PYQDeck for Android
Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.