Ajax MCQs

Ajax MCQs

These Ajax multiple-choice questions and their answers will help you strengthen your grip on the subject of Ajax. You can prepare for an upcoming exam or job interview with these Ajax MCQs.
So scroll down and start answering.

1: Which protocol is used to transfer data in an AJAX request?

A.   Asynchronous Binary Transfer Protocol, ABTP

B.   Hypertext Transfer Protocol, HTTP

C.   AJAX Object Protocol, AOP

D.   Advanced Server Protocol, ASP

2: Which of the HTTP actions is an Ajax XML HTTP request capable of sending to a server?

A.   GET, POST and PUT


C.   GET and POST


3: What is the JavaScript syntax for generating an XML HTTP request object and assigning it to the "xhr" variable? Consider only modern browsers, plus IE7 and above.

A.   var xhr = navigator.XMLHTTPRequest();

B.   var xhr = new XMLHTTPRequest();

C.   var xhr = new XMLHttpRequest();

D.   var xhr = window.XmlHTTPRequest();

4: Is it possible to add custom HTTP header to ajax request?

A.   No, it is not possible

B.   Yes, it is possible. setRequestHeader() method of XMLHttpRequest object can be used to add a custom HTTP header

C.   Yes, it is possible. Custom HTTP header can be added while initializing a request with init() method

D.   Yes, it is possible. Custom HTTP header can be added while initializing a request with open() method

5: What is the difference between the XMLHttpRequest object's .status and .statusText attributes?

A.   .statusText is the more widely supported of the two across browsers

B.   .status returns a numeric-only code instead of the full HTTP response, which can be found in .statusText

C.   .statusText is not a valid attribute of the XMLHttpRequest object

D.   .status is read-only, while .statusText can be modified

6: What is the purpose of Ajax long-polling?

A.   To allow cross-domain data transfer

B.   To check server-side functionality before executing client-side code

C.   To allow offline functionality in Ajax-driven web applications

D.   To keep a server connection open for two-way communication

7: For the "same origin policy" to always allow an Ajax request, what attributes must be the same between the requesting context and the server?

A.   Domain name, protocol, and port

B.   IP subnet

C.   Second-level domain only

D.   Full domain name

8: What is the preferred method for maintaining back/forward button and crawler functionality in Ajax-driven web applications?

A.   There is no effective method

B.   < or > in the URL

C.   history.pushState()

D.   window.location()

9: Which HTML5 feature can improve the experience of a user using the "back" and "forward" buttons when using AJAX techniques?

A.   New browser chrome events: onbackbuttonpressed and onforwardbuttonpressed.

B.   The history API with pushState, replaceState and history events.

C.   The storage API with css3 full page state saving.

D.   The version API that allows versioning page interactions.

10: What does the acronym "blob" stand for when referring to data types?

A.   It is not an acronym

B.   binned large ordinal byte

C.   binary large object

D.   bytes left over from bitstream

11: In standard JavaScript, what makes asynchronous execution of Ajax calls possible?

A.   Events and callbacks

B.   Multi-threaded operations

C.   Deferrals and promises

12: Which browser features and/or technologies must be enabled, at a minimum, for AJAX techniques to function properly?

A.   A Java plugin must be installed and enabled.

B.   Cookies must be enabled.

C.   A Flash plugin must be installed

D.   JavaScript must be enabled.

E.   Private browsing must be enabled.

13: What are the advantages of using JavaScript libraries (like jQuery) to implement Ajax?

A.   There is no advantage

B.   Fewer HTTP requests and smaller loaded resources

C.   Better cross-browser compatibility and faster speed of development

14: The primary benefit of using AJAX techniques in a web application is:

A.   It makes pages more easily bookmarked, shared and navigated by users using standard browser controls.

B.   It makes web applications more easily crawlable by search engines like Google, Yahoo and Bing.

C.   It makes it easier to create accessible (usable by people of all abilities and disabilities) web pages

D.   It allows web applications to send asynchronous data requests to a server without a user initiated page load.

E.   It makes web applications "advanced".

15: Which method on the XMLHttpRequest object is used to send custom HTTP headers with a request?

A.   setXHRHeader

B.   setRequestHeader

C.   sendAdditionalRequestHeader

D.   addHeader

16: What is the value of the "status" attribute of the completed XMLHttpRequest object if the Ajax request has pulled the response data from the browser cache? Consider only non-IE browsers.

A.   301

B.   304

C.   200

D.   "cached"

17: The onreadystatechange change event is used to invoke behavior when

A.   the browser window is closed or resized.

B.   elements on a page change appearance.

C.   users navigate away from a page with unsaved or uncommitted changes.

D.   the status of the asynchronous request changes.

E.   a user indicates they are ready to continue from a dialog prompt.

18: If an Ajax request loads JSON-formatted responseText into the variable returnedData, what code will turn the data into a readable JSON object in modern browsers, including IE8 and above?

A.   JSON.parse(returnedData);

B.   returnedData.parse("JSON");

C.   JSON.stringify(returnedData);

D.   returnedData.parse();

19: True or false? A GET request submitted through Ajax can never cause the server to delete data.

A.   True

B.   False

20: Ajax can be used to open a connection from the server to the browser without the browser making an explicit request.

A.   False

B.   true

21: How do you manually abort an Ajax request after a certain amount of time?

A.   Supply a "timeout" argument in the request's .open() method

B.   Using setTimeout(), clearTimeout() and .abort()

C.   There is no way to manually timeout Ajax requests

22: Most JavaScript libraries that provide AJAX support include this header in AJAX requests by default.

A.   X-Request-Option: Asynchronous

B.   X-Forwarded-For: XMLHttpRequest

C.   X-Request-Type: AJAX

D.   Proxy-Authorization: Asynchronous

E.   X-Requested-With: XMLHttpRequest

23: Can an XMLHttpRequest object be used to receive binary data?

A.   Yes, but only when transferring image files.

B.   Yes, but only in newer browsers by using the responseType property specified in the Level 2 XHR specification.

C.   Yes, in newer browsers using the responseType property and in older browsers by overriding the mime type of the response.

D.   No, XHR requests only allow text transfer between server and client.

24: What does JSON do?

A.   A binary protocol, based on JavaScript, for the transmission of application state

B.   A data serialization and interchange format using a subset of JavaScript syntax

C.   A lightweight, HTML5, browser-based database for storing client-side data.

D.   A browser-only data serialization and interchange format based on JavaScript.

E.   A JavaScript library for transmitting data between clients and servers.

25: True or false? Ajax can be used to open a connection from the server to the browser without the browser making an explicit request.

A.   True

B.   False

26: Can you make an XMLHttpRequest asynchronous call to a page on a different top level domain from the current page's top level domain?

A.   Yes, when the P3P header is returned from the server and properly configured.

B.   Yes, always.

C.   In newer browsers cross-domain requests can be configured but only when servers use special headers to explicitly allow some cross domain requests.

D.   No, browser sandboxing rules prevent any asynchronous requests between different document domains.

E.   Yes, when the two top level domains share the same SSL certificate.

27: Can you perform file uploads using AJAX requests alone?

A.   Yes

B.   Yes, but only when using newer browsers and HTML5 features.

C.   No, not without additional plugins and hacks.

28: AJAX applications are browser- and platform-dependent!

A.   False

B.   True

29: How will the response be parsed if responseType is set to "document" and the request has been made asynchronously?

A.   as an empty string

B.   as binary

C.   as text/html

D.   none of the above

E.   as text/xml

30: What is the value of the .status attribute of the completed XMLHttpRequest object if the Ajax request needed to follow a server-side redirect before successfully finding the intended resource?

A.   301

B.   304

C.   200

D.   "redirected"

31: If the server is expecting JSON-formatted information in the request, what code will turn the JavaScript object dataToSend into data you can send to the server (consider modern browsers only, including IE8 and above)?

A.   JSON.stringify(dataToSend);

B.   dataToSend.stringify();

C.   JSON.parse(dataToSend);

D.   dataToSend.stringify("serial");

32: What's wrong with the following code? function check_for_request_done() { if (xhr.readyState == 4) { clearInterval(timer); do_something_with_result(xhr); } } var xhr = new XMLHttpRequest(); xhr.open("GET", "/resource", true); xhr.send(); var timer = setInterval(check_for_request_done, 100);

A.   The resource is being fetched synchronously so there's no need to wait for a response.

B.   The wrong readystate value is being checked for a complete request. The response should only be used when readyState == 5.

C.   The timer interval (100ms) is way too fast, a longer polling interval should be chosen to detect for response.

D.   This code is polling a timer rather using the onreadystatechange event to check the state of the async request.

33: What is the name of the object which provides CORS support in Internet Explorer 8 and Internet Explorer 9?

A.   XDomainRequest

B.   CDomainRequest

C.   CORSRequest

D.   None of the above

E.   XMLHttpRequest

34: What does CORS stand for?

A.   Confirmed origin response status

B.   Cross-origin resource sharing

C.   Cross-origin request system

D.   Central organized repository service

35: What is the CORS-enabled Ajax request object constructor in IE8-9?

A.   new CorsRequest();

B.   new XMLHttpRequest();

C.   new CORSRequest();

D.   new XDomainRequest();

36: What is XSS?

A.   A JavaScript rendering engine

B.   Malicious client-side code injection

C.   A development framework that assists in writing Ajax-driven applications

D.   An extensible stylesheet format designed to be used with Ajax

37: How can you load JavaScript from a different file into your web application?



C.   <script> tags

D.   All of these

38: What is the syntax for the event listener that monitors whether the XMLHttpRequest object's readyState attribute has changed?

A.   onreadystatechange

B.   onprogress

C.   onReadyStateChange

D.   onProgress

39: How does Google recommend you make an Ajax-dependent page accessible to their web crawler?

A.   Use Ajax to progressively enhance server-side processing, rather than to replace it

B.   Add a <meta> tag with the value "dynamic='true'"

C.   Use a robots.txt file to transmit the relevant data to the crawler

40: When your Ajax request is complete, what attribute of the XML HTTP request object contains the returned data?

A.   response

B.   responseText

C.   responseData

D.   returnedData

41: What is the proper way to execute a callback function while making a "synchronous" request?

A.   Callback functions are used with "asynchronous" requests only

B.   req.readyState = callback_function_name;

C.   req.trigger(callback_function_name);

D.   req.onreadystatechange = callback_function_name;

42: How would you configure a *synchronous* GET request to "/resource" after instantiating a new XMLHttpRequest object: var xhr = new XMLHttpRequest();?

A.   xhr.open("GET", "/resource", false);

B.   xhr.open("GET", "/resource", true);

C.   xhr.sync("GET", "/resource");

D.   xhr.open("GET", "/resource");

E.   xhr.request("/resource");

43: Which readystate value indicates the response has been fully received from the asynchronous request?

A.   1 (readystate received)

B.   true (response received)

C.   4 (readystate complete)

D.   "OK" (response good)

E.   200 (response OK)

44: What is the technical limitation to implementing user login entirely on the client side using Ajax?

A.   There is no technical limitation; it is a common practice

B.   Client-side data is not persisted across browser sessions

C.   Client-side data storage is limited to 5MB

D.   Client-side code is inherently insecure

45: According to the W3C specification, which HTTP methods should throw a security exception when used with XMLHttpRequest?






46: Your cross-origin Ajax request is causing your console to throw the error "Resource interpreted as Script but transferred with MIME type application/json. Uncaught SyntaxError: Unexpected token :" What might be happening?

A.   The server is returning an unencapsulated JSON object which is being executed as JSONP

B.   You used the incorrect callback parameter in your request URL

C.   The server is rejecting your cross-origin request because you did not supply the correct headers

D.   The wrong MIME type has been selected in your Ajax configuration

47: After a request completes, which property of the XMLHttpRequest object can be used to retrieve a DOM representation of a remote XML document?

A.   documentXML

B.   responseXML

C.   XMLDoc

D.   XMLDom

E.   responseText

48: Which of these is NOT an advantage of using Ajax over server-side processing?

A.   Lazy-loading of resources

B.   Cross-browser compatibility

C.   Client-side responsiveness

D.   Reduced server processing load

49: What happens if an Ajax call completes (and calls its callback function) when other JavaScript is currently running?

A.   The Ajax callback function will run immediately in another thread, allowing the currently-running code to complete as normal

B.   The currently-running code will terminate, and the Ajax callback function will be called immediately

C.   The Ajax callback function will be queued until the currently-running code completes

50: What arguments MUST be supplied to an XMLHttpRequest object's .open() method, and in what order?

A.   URL as string, HTTP method as string, CORS flag as boolean

B.   URL as string, HTTP method as string, URL parameters as string

C.   HTTP method as string, URL as string, async flag as boolean, username as string, password as string

D.   HTTP method as string, URL as string