Elance AJAX Test Answers 2015



Which protocol is used to transfer data in an AJAX request?
Advanced Server Protocol, ASP
Asynchronous Binary Transfer Protocol, ABTP
Hypertext Transfer Protocol, HTTP
AJAX Object Protocol, AOP


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);
The wrong readystate value is being checked for a complete request. The response should only be used when readyState == 5.
The timer interval (100ms) is way too fast, a longer polling interval should be chosen to detect for response.
This code is polling a timer rather using the onreadystatechange event to check the state of the async request.
The resource is being fetched synchronously so there's no need to wait for a response.


What is the difference between the XMLHttpRequest object's .status and .statusText attributes?
.status is read-only, while .statusText can be modified
.statusText is not a valid attribute of the XMLHttpRequest object
.statusText is the more widely supported of the two across browsers
.status returns a numeric-only code instead of the full HTTP response, which can be found in .statusText


Is it possible to add custom HTTP header to ajax request?
Yes, it is possible. Custom HTTP header can be added while initializing a request with open() method
Yes, it is possible. setRequestHeader() method of XMLHttpRequest object can be used to add a custom HTTP header
No, it is not possible
Yes, it is possible. Custom HTTP header can be added while initializing a request with init() method


The onreadystatechange change event is used to invoke behavior when
elements on a page change appearance.
the browser window is closed or resized.
the status of the asynchronous request changes.
users navigate away from a page with unsaved or uncommitted changes.
a user indicates they are ready to continue from a dialog prompt.


Which method on the XMLHttpRequest object is used to send custom HTTP headers with a request?
setXHRHeader
sendAdditionalRequestHeader
addHeader
setRequestHeader


When using async=true in xmlhttp.open function
specify a function to execute when the response is ready in the onreadystatechange event
server crashed
response is not constructed
connection not established


What does the acronym "blob" stand for when referring to data types?
It is not an acronym
binary large object
bytes left over from bitstream
binned large ordinal byte


Aalways use POST requests in xmlhttp.open when
update a file or database on the server
does not require to send user inputs
data size is small
security is not an issue


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.
"cached"
301
200
304


For the "same origin policy" to always allow an Ajax request, what attributes must be the same between the requesting context and the server?
Domain name, protocol, and port
Second-level domain only
Full domain name
IP subnet


Which HTML5 feature can improve the experience of a user using the "back" and "forward" buttons when using AJAX techniques?
The history API with pushState, replaceState and history events.
The storage API with css3 full page state saving.
The version API that allows versioning page interactions.
New browser chrome events: onbackbuttonpressed and onforwardbuttonpressed.


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.
var xhr = navigator.XMLHTTPRequest();
var xhr = new XMLHTTPRequest();
var xhr = new XMLHttpRequest();
var xhr = window.XmlHTTPRequest();


In standard JavaScript, what makes asynchronous execution of Ajax calls possible?
Multi-threaded operations
Deferrals and promises
Events and callbacks


Which browser features and/or technologies must be enabled, at a minimum, for AJAX techniques to function properly?
Private browsing must be enabled.
Cookies must be enabled.
JavaScript must be enabled.
A Java plugin must be installed and enabled.
A Flash plugin must be installed


What are the advantages of using JavaScript libraries (like jQuery) to implement Ajax?
Better cross-browser compatibility and faster speed of development
There is no advantage
Fewer HTTP requests and smaller loaded resources


The primary benefit of using AJAX techniques in a web application is:
It makes web applications "advanced".
It allows web applications to send asynchronous data requests to a server without a user initiated page load.
It makes pages more easily bookmarked, shared and navigated by users using standard browser controls.
It makes it easier to create accessible (usable by people of all abilities and disabilities) web pages
It makes web applications more easily crawlable by search engines like Google, Yahoo and Bing.


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?
JSON.parse(returnedData);
returnedData.parse();
returnedData.parse("JSON");
JSON.stringify(returnedData);


What is the preferred method for maintaining back/forward button and crawler functionality in Ajax-driven web applications?
< or > in the URL
window.location()
There is no effective method
history.pushState()


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


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


How do you manually abort an Ajax request after a certain amount of time?
There is no way to manually timeout Ajax requests
Using setTimeout(), clearTimeout() and .abort()
Supply a "timeout" argument in the request's .open() method


What does JSON do?
A binary protocol, based on JavaScript, for the transmission of application state
A browser-only data serialization and interchange format based on JavaScript.
A JavaScript library for transmitting data between clients and servers.
A lightweight, HTML5, browser-based database for storing client-side data.
A data serialization and interchange format using a subset of JavaScript syntax


AJAX applications are browser- and platform-dependent!
False
True


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


Most JavaScript libraries that provide AJAX support include this header in AJAX requests by default.
X-Forwarded-For: XMLHttpRequest
X-Requested-With: XMLHttpRequest
Proxy-Authorization: Asynchronous
X-Request-Type: AJAX
X-Request-Option: Asynchronous


What is the purpose of Ajax long-polling?
To keep a server connection open for two-way communication
To check server-side functionality before executing client-side code
To allow offline functionality in Ajax-driven web applications
To allow cross-domain data transfer


Can an XMLHttpRequest object be used to receive binary data?
Yes, but only when transferring image files.
Yes, but only in newer browsers by using the responseType property specified in the Level 2 XHR specification.
No, XHR requests only allow text transfer between server and client.
Yes, in newer browsers using the responseType property and in older browsers by overriding the mime type of the response.


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?
"redirected"
301
200
304


How response will be parsed if responseType is set to "document" and the request has been made asynchronously?
as a text/xml stream
as a text/html stream
as an empty string
as a binary stream
none of the above


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)?
JSON.parse(dataToSend);
dataToSend.stringify();
JSON.stringify(dataToSend);
dataToSend.stringify("serial");


Can you perform file uploads using AJAX requests alone?
Yes
No, not without additional plugins and hacks.
Yes, but only when using newer browsers and HTML5 features.


Can you make an XMLHttpRequest asynchronous call to a page on a different top level domain from the current page's top level domain?
In newer browsers cross-domain requests can be configured but only when servers use special headers to explicitly allow some cross domain requests.
Yes, when the two top level domains share the same SSL certificate.
Yes, always.
No, browser sandboxing rules prevent any asynchronous requests between different document domains.
Yes, when the P3P header is returned from the server and properly configured.


What is XSS?
An extensible stylesheet format designed to be used with Ajax
A development framework that assists in writing Ajax-driven applications
A JavaScript rendering engine
Malicious client-side code injection


Which of the HTTP actions is an Ajax XML HTTP request capable of sending to a server?
GET, POST and PUT
GET, POST, and DELETE
GET, POST, PUT, and DELETE
GET and POST


What is the syntax for the event listener that monitors whether the XMLHttpRequest object's readyState attribute has changed?
onProgress
onprogress
onreadystatechange
onReadyStateChange


Which readystate value indicates the response has been fully received from the asynchronous request?
true (response received)
4 (readystate complete)
200 (response OK)
"OK" (response good)
1 (readystate received)


What is the CORS-enabled Ajax request object constructor in IE8-9?
new XMLHttpRequest();
new CorsRequest();
new CORSRequest();
new XDomainRequest();


How can you load JavaScript from a different file into your web application?
<script> tags
CORS
All of these
JSONP


When your Ajax request is complete, what attribute of the XML HTTP request object contains the returned data?
returnedData
response
responseData
responseText


What is the name of the object which provides CORS support in Internet Explorer 8 and Internet Explorer 9?
XDomainRequest
None of the above
XMLHttpRequest
CDomainRequest
CORSRequest


How does Google recommend you make an Ajax-dependent page accessible to their web crawler?
Add a <meta> tag with the value "dynamic='true'"
Use a robots.txt file to transmit the relevant data to the crawler
Use Ajax to progressively enhance server-side processing, rather than to replace it


How would you configure a *synchronous* GET request to "/resource" after instantiating a new XMLHttpRequest object: var xhr = new XMLHttpRequest();?
xhr.open("GET", "/resource", true);
xhr.open("GET", "/resource");
xhr.open("GET", "/resource", false);
xhr.sync("GET", "/resource");
xhr.request("/resource");


What HTML attribute would you use to indicate to a screenreader that an element of the page may update using Ajax while out of the user's focus?
aria-updates
aria-live
aria-polite
aria-active


According to the W3C specification, which HTTP methods should throw a security exception when used with XMLHttpRequest?
DRAFT, VALIDATE or SAVE
PATCH or PLACE
PATCH, HEAD, or OPTIONS
CONNECT, TRACE, or TRACK
OPTIONS, GET, PUT


What does CORS stand for?
Central organized repository service
Cross-origin resource sharing
Confirmed origin response status
Cross-origin request system


Which of these is NOT an advantage of using Ajax over server-side processing?
Lazy-loading of resources
Client-side responsiveness
Cross-browser compatibility
Reduced server processing load


What is the proper way to execute a callback function while making a "synchronous" request?
Callback functions are used with "asynchronous" requests only
req.readyState = callback_function_name;
req.onreadystatechange = callback_function_name;
req.trigger(callback_function_name);


What value of the XMLHttpRequest object's readystate attribute indicates that the response data (i.e. not the headers) is currently being sent back from the server?
"loading"
2
3
The readystate attribute does not provide this information


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?
The wrong MIME type has been selected in your Ajax configuration
You used the incorrect callback parameter in your request URL
The server is rejecting your cross-origin request because you did not supply the correct headers
The server is returning an unencapsulated JSON object which is being executed as JSONP


After a request completes, which property of the XMLHttpRequest object can be used to retrieve a DOM representation of a remote XML document?
responseText
responseXML
XMLDoc
XMLDom
documentXML


What is the technical limitation to implementing user login entirely on the client side using Ajax?
Client-side data storage is limited to 5MB
There is no technical limitation; it is a common practice
Client-side data is not persisted across browser sessions
Client-side code is inherently insecure


What HTTP response header is expected in reply to a CORS request?
Allow-CORS
Cross-Origin-Permissions
Access-Control-Allow-Origin
Allow-Cross-Origin-Access


You've created an XMLHttpRequest object, xhr, and properly called open as well as send on the object. When you check xhr.status and it's 0 and your responseText is null. What's the most likely explanation of what happened?
The target resource was served from the browser's cache.
The request has not yet connected to the server.
The browser has initiated too many simultaneous XHR requests and this request has been queued.
The server encountered an unknown error.
Your request was canceled either due to a failed connection or a user action.


You're issuing a request to "/resource" using XMLHttpRequest (xhr) where the server returns a 301 or 302 status code, what happens?
The XHR object will automatically and transparently follow the redirects to the new location for the resource, unless it's on a different domain.
Depends on how the XHR object is configured. If xhr.redirects=false, you will need to manually issue new requests otherwise it will automatically follow 301 and 302 redirects, unless the location is on a different domain.
The readystate will advance to 4 but the responseText and responseXML will be null. You will need to issue a new request to the destination of xhr.getResponseHeader("Location").
The readystate will halt at 3 and you must detect the 301 or 302 header and call xhr.continue() for each 301/302 response.


Ajax is frequently expanded as "asynchronous JavaScript and XML," which is misleading. Which of these words is not central to Ajax's functionality?
asynchronous
JavaScript
asynchronous and XML
XML


What happens if an Ajax call completes (and calls its callback function) when other JavaScript is currently running?
The Ajax callback function will run immediately in another thread, allowing the currently-running code to complete as normal
The currently-running code will terminate, and the Ajax callback function will be called immediately
The Ajax callback function will be queued until the currently-running code completes


When receiving an image from the server, the responseType attribute of your XMLHttpRequest object must be set to:
"arraybuffer" or "blob"
"arraybuffer"
"image"
"blob"


What XMLHttpRequest method is used to override MIME type returned by the server?
setRequestHeader()
setHeader()
overrideMimeType()
init()


What is the value of the response property of XMLHttpRequest object if readyState property equal to 3?
null
0
empty string
partial response body
undefined


How do you detect errors in Ajax REQUESTS?
the onerror event
check if .readyState !== 4
check if .status !== 200


How does JSONP work?
It encodes server responses in a special data type that is ignored by the browser's JavaScript parser
It makes server response text act like an injected <script> element
It sends an HTTP "Access-Control-Allow-Origin" header to the server that asks for permission to make a cross-origin request


What arguments MUST be supplied to an XMLHttpRequest object's .open() method, and in what order?
HTTP method as string, URL as string
HTTP method as string, URL as string, async flag as boolean, username as string, password as string
URL as string, HTTP method as string, CORS flag as boolean
URL as string, HTTP method as string, URL parameters as string


Which property of the popstate event contains a copy of the history entry's state object?
none of the above
historyState
state
currentState
copyState


In non-IE browsers, what attribute should you check your XMLHttpRequest object for in order to see if it supports CORS?
xDomain
crossDomain
hasCors
withCredentials