PrepIQ Ajax Programming Ultimate Exam, Exams of Technology

This exam tests your understanding and skills in using Asynchronous JavaScript and XML (AJAX). Topics include handling HTTP requests, updating webpages dynamically, and implementing AJAX in various applications. Designed for web developers wanting to master AJAX techniques.

Typology: Exams

2025/2026

Available from 05/03/2026

shilpi-jain-3
shilpi-jain-3 🇮🇳

2.5

(11)

80K documents

1 / 116

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PrepIQ Ajax Programming Ultimate
Exam
**Question 1. Which of the following best describes the core purpose of
AJAX?**
A) To replace JavaScript with a new language
B) To allow asynchronous communication between client and server without
a full page reload
C) To convert XML documents into HTML pages automatically
D) To enforce synchronous page loading for better SEO
Answer: B
Explanation: AJAX enables background HTTP requests, letting parts of a page
update without reloading the entire document.
**Question 2. In the context of AJAX, what does the term “asynchronous”
mean?**
A) The server processes requests in a separate thread
B) The browser blocks UI interactions until a response is received
C) The client can continue executing other code while waiting for a server
response
D) The request is sent using the FTP protocol
Answer: C
Explanation: Asynchronous requests allow JavaScript to keep running while
the network operation completes.
**Question 3. Which of the following technologies is NOT part of the classic
AJAX stack?**
A) JavaScript
B) XMLHttpRequest
C) CSS
D) SOAP
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download PrepIQ Ajax Programming Ultimate Exam and more Exams Technology in PDF only on Docsity!

Exam

Question 1. Which of the following best describes the core purpose of AJAX? A) To replace JavaScript with a new language B) To allow asynchronous communication between client and server without a full page reload C) To convert XML documents into HTML pages automatically D) To enforce synchronous page loading for better SEO Answer: B Explanation: AJAX enables background HTTP requests, letting parts of a page update without reloading the entire document. Question 2. In the context of AJAX, what does the term “asynchronous” mean? A) The server processes requests in a separate thread B) The browser blocks UI interactions until a response is received C) The client can continue executing other code while waiting for a server response D) The request is sent using the FTP protocol Answer: C Explanation: Asynchronous requests allow JavaScript to keep running while the network operation completes. Question 3. Which of the following technologies is NOT part of the classic AJAX stack? A) JavaScript B) XMLHttpRequest C) CSS D) SOAP

Exam

Answer: D Explanation: SOAP is a protocol for web services, not a core AJAX component. AJAX typically uses XHR, JavaScript, HTML/CSS, and JSON/XML. Question 4. What is the default value of the async flag when calling xhr.open(method, url, async)? A) true B) false C) null D) undefined Answer: A Explanation: If the third argument is omitted, open() creates an asynchronous request (async = true). Question 5. Which HTTP method should be used with XMLHttpRequest when you want to send data that modifies server state but does not retrieve data? A) GET B) POST C) HEAD D) OPTIONS Answer: B Explanation: POST is intended for submitting data that creates or updates resources on the server. Question 6. When using XMLHttpRequest, which readyState value indicates that the operation is complete and the response is ready? A) 1 B) 2

Exam

A) JSON.parse() B) eval() C) JSON.convert() D) Object.fromJSON() Answer: A Explanation: JSON.parse() parses a JSON string according to the JSON specification, avoiding the security risks of eval(). Question 10. When sending a POST request with JSON payload using XMLHttpRequest, which header must be set to inform the server of the payload type? A) Accept: application/xml B) Content-Type: application/json C) X-Requested-With: XMLHttpRequest D) Cache-Control: no-cache Answer: B Explanation: Content-Type: application/json tells the server that the request body is JSON-formatted. Question 11. Which of the following is a correct way to create an XMLHttpRequest object that works in older versions of Internet Explorer (IE 6-8)? A) new XMLHttpRequest() only B) new ActiveXObject("Microsoft.XMLHTTP") only C) window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") D) document.createElement("xhr") Answer: C

Exam

Explanation: The conditional expression checks for native support and falls back to the ActiveXObject for legacy IE. Question 12. What does the setRequestHeader() method of XMLHttpRequest allow you to do? A) Change the URL of the request after it has been sent B) Define custom HTTP request headers before sending the request C) Modify the response body received from the server D) Set the HTTP status code that the client will receive Answer: B Explanation: setRequestHeader(name, value) adds or modifies request headers such as Content-Type or Authorization. Question 13. Which of the following correctly encodes query parameters for a GET request? A) encodeURI() on the whole URL string B) encodeURIComponent() on each parameter value and then concatenate C) JSON.stringify() the parameters object D) No encoding is required for GET parameters Answer: B Explanation: encodeURIComponent() must be applied to each parameter value to ensure special characters are safely transmitted. Question 14. In the Fetch API, which method returns a Promise that resolves to a Response object? A) fetch() B) XMLHttpRequest.send() C) axios.get()

Exam

fetch('/api/data') .then(r => r.json()) .then(d => console.log(d)) .catch(e => console.error(e));

A) `await fetch('/api/data'); const d = await response.json(); console.log(d);` B) `async function load(){ try{ const r = await fetch('/api/data'); const d = await r.json(); console.log(d);} catch(e){ console.error(e);} } load();` C) `fetch('/api/data').await().json().await();` D) `async fetch('/api/data').then(...);` Answer: B Explanation: `async` function with `await` for each asynchronous step and a `try/catch` block mirrors the original chain. **Question 18. Which of the following techniques is most appropriate for implementing a real-time chat feature?** A) Short polling with `setInterval` and AJAX B) Long polling using `XMLHttpRequest` that holds the connection open C) WebSockets with a persistent, full-duplex connection D) Server-sent events (SSE) only Answer: C Explanation: WebSockets provide low-latency, bidirectional communication ideal for chat, whereas polling introduces unnecessary latency. **Question 19. What is the purpose of the `FormData` API when used with `XMLHttpRequest`?** A) To parse JSON strings into form fields B) To serialize plain objects into URL-encoded query strings ## Exam C) To construct a set of key/value pairs representing form fields, including files, for multipart/form-data submissions D) To encrypt form data before sending Answer: C Explanation: `FormData` handles binary data and file uploads, automatically setting the appropriate multipart request headers. **Question 20. Which method of the `Response` object returned by `fetch()` is used to retrieve the response body as JSON?** A) `text()` B) `blob()` C) `json()` D) `arrayBuffer()` Answer: C Explanation: `response.json()` parses the body text as JSON and returns a Promise that resolves to the resulting object. **Question 21. In an `XMLHttpRequest` response, which property should you use to access XML data as a DOM tree?** A) `responseText` B) `responseXML` C) `responseJSON` D) `responseData` Answer: B Explanation: `responseXML` returns an XML Document object that can be traversed with standard DOM methods. ## Exam Answer: C Explanation: jQuery abstracts boilerplate code, normalizes browser differences, and offers convenient options like `dataType`, `success`, and `error`. **Question 25. Which HTTP header is commonly sent by browsers to indicate that a request was made via AJAX?** A) `X-Requested-With: XMLHttpRequest` B) `Accept: application/json` C) `Content-Type: multipart/form-data` D) `Cache-Control: no-cache` Answer: A Explanation: Many libraries (including jQuery) set `X-Requested-With: XMLHttpRequest` so the server can detect an AJAX request. **Question 26. In the context of AJAX security, which attack exploits the fact that a malicious site can cause a victim’s browser to send authenticated requests to a trusted site?** A) XSS (Cross-Site Scripting) B) CSRF (Cross-Site Request Forgery) C) SQL Injection D) Clickjacking Answer: B Explanation: CSRF tricks a user’s browser into performing unwanted actions on a site where the user is authenticated. **Question 27. Which of the following is a recommended mitigation technique against CSRF in AJAX requests?** A) Disabling JavaScript entirely ## Exam B) Adding a custom request header (e.g., `X-CSRF-Token`) with a token validated server-side C) Using `GET` requests for all state-changing operations D) Storing sensitive data in localStorage Answer: B Explanation: Sending a server-generated token in a custom header (or hidden form field) allows the server to verify the request’s legitimacy. **Question 28. When a page uses AJAX to load content dynamically, which accessibility concern should be addressed?** A) Ensuring the page title never changes B) Providing alternative static content for users with JavaScript disabled C) Hiding all ARIA attributes D) Disabling keyboard navigation Answer: B Explanation: Graceful degradation ensures that users without JavaScript still receive usable content. **Question 29. Which JavaScript pattern helps prevent sending too many AJAX requests when a user types quickly into a search box?** A) Throttling B) Recursion C) Memoization D) Singleton Answer: A Explanation: Throttling limits the rate at which a function (e.g., the AJAX call) can be invoked, reducing server load. ## Exam Answer: A Explanation: Setting `xhr.responseType = "json"` makes `xhr.response` return a parsed JavaScript object. **Question 33. When using `fetch()`, how can you abort an in-progress request?** A) Call `xhr.abort()` on the returned object B) Use an `AbortController` and pass its signal to `fetch()` C) Set `async: false` in the options object D) You cannot abort a fetch request once started Answer: B Explanation: `AbortController` provides a signal that, when triggered, aborts the associated fetch operation. **Question 34. Which of the following statements about JSONP is correct?** A) JSONP is a secure way to perform cross-origin POST requests B) JSONP works by injecting a ` ## Exam ## C) 204 ## D) 301 Answer: B Explanation: 201 (Created) signals that the server successfully created a new resource in response to the request. **Question 36. In a typical AJAX request cycle, which event fires first?** A) `onload` of the XHR object B) `readystatechange` with `readyState === 1` (opened) C) `onerror` D) `onprogress` Answer: B Explanation: After calling `open()`, the XHR’s `readyState` becomes 1, triggering the first `readystatechange` event. **Question 37. What is the effect of setting `xhr.withCredentials = true`?** A) The request will be sent using the HTTP PUT method automatically B) Cookies and HTTP authentication information will be sent with cross-origin requests C) The response will be cached for 24 hours D) The request will be encrypted with a custom algorithm Answer: B Explanation: `withCredentials` enables sending cookies, authorization headers, and TLS client certificates in cross-origin XHR requests. **Question 38. Which of the following is a correct way to handle a network timeout with `XMLHttpRequest`?** A) Set `xhr.timeout = 5000;` and define `xhr.ontimeout` handler ## Exam A) `type` B) `dataType` C) `contentType` D) `processData` Answer: B Explanation: `dataType` can be set to `"json"`, `"xml"`, `"html"`, etc., influencing how jQuery parses the response. **Question 42. Which of the following statements about the `innerHTML` property is TRUE when injecting AJAX-retrieved content?** A) It automatically sanitizes the content to prevent XSS B) It replaces the entire element’s children with the provided markup, which may include scripts that execute immediately C) It can only accept plain text, not HTML markup D) It updates the browser’s history stack automatically Answer: B Explanation: `innerHTML` inserts raw HTML; if the content contains ` ## Exam Explanation: Long polling reduces request overhead by having the server delay its response until data changes. **Question 44. Which JavaScript method can be used to convert a DOM element into a string of HTML?** A) `element.outerHTML` B) `element.innerText` C) `element.textContent` D) `element.cloneNode()` Answer: A Explanation: `outerHTML` returns a serialized HTML string representing the element and its descendants. **Question 45. Which HTTP response header can be used to prevent browsers from caching an AJAX response?** A) `Expires: 0` B) `Cache-Control: no-store` C) `Pragma: no-cache` D) All of the above Answer: D Explanation: All three headers instruct browsers not to store the response in cache. **Question 46. In a `fetch()` call, which method of the `Response` object would you use to obtain a Blob representing binary data (e.g., an image)?** A) `arrayBuffer()` B) `blob()` C) `json()` ## Exam A) `application/json` B) `multipart/form-data` (including boundary) C) `text/plain` D) **Do not set** it; the browser will automatically set the correct multipart boundary Answer: D Explanation: The browser automatically generates the correct `Content-Type` with a unique boundary when `FormData` is used. **Question 50. Which of the following is an advantage of using JSON over XML for AJAX responses?** A) JSON supports comments, making it more readable B) JSON can be directly parsed into native JavaScript objects without extra conversion C) XML provides built-in schema validation, which JSON lacks D) JSON requires less bandwidth due to mandatory compression Answer: B Explanation: JSON maps naturally to JavaScript objects, allowing `JSON.parse()` to produce usable data with minimal overhead. **Question 51. In the context of AJAX, what does “graceful degradation” refer to?** A) Providing a fallback experience for browsers that do not support JavaScript or AJAX B) Automatically converting all AJAX calls into server-side includes C) Encrypting all AJAX traffic with a custom algorithm D) Using only synchronous XHR to ensure compatibility Answer: A ## Exam Explanation: Graceful degradation ensures the site remains functional (perhaps with full page reloads) when modern features are unavailable. **Question 52. Which of the following is the correct way to add a click event listener that triggers an AJAX request using vanilla JavaScript?** A) `document.getElementById('btn').onclick = function(){ /* XHR code */ };` B) `$('#btn').click(function(){ /* XHR code */ });` C) `document.querySelector('#btn').addEventListener('click', ajaxFunction);` D) Both A and C are valid, but C is the modern standard Answer: D Explanation: Both approaches work, but `addEventListener` is the recommended modern method. **Question 53. Which of the following HTTP methods is considered safe (does not modify server state) and therefore can be cached by browsers?** A) POST B) PUT C) DELETE D) GET Answer: D Explanation: GET should be side-effect-free and is eligible for caching according to HTTP specifications. **Question 54. When using the Fetch API, how can you read the raw binary data of a response as an `ArrayBuffer`?** A) `response.text()` B) `response.json()` C) `response.arrayBuffer()`