Tuesday, 30 December 2014

Elance Ajax Test Answers

Which protocol is used to transfer data in an AJAX request?
Hypertext Transfer Protocol, HTTP


Which property of the popstate event contains a copy of the history entry’s state object?
state


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);

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




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




What is the value of the response property of XMLHttpRequest object if readyState property equal to 3?
null


What arguments MUST be supplied to an XMLHttpRequest object’s .open() method, and in what order?
HTTP method as string, URL as string


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


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.


How does JSONP work?
It makes server response text act like an injected <script> element


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



How do you detect errors in Ajax REQUESTS?
the onerror event



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?
Your request was canceled either due to a failed connection or a user action.




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



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



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.
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 server is returning an unencapsulated JSON object which is being executed as JSONP
Which property of the popstate event contains a copy of the history entry’s state object?
state

What is the technical limitation to implementing user login entirely on the client side using Ajax?
Client-side code is inherently insecure

Which readystate value indicates the response has been fully received from the asynchronous request?
4 (readystate complete)
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.stringify(dataToSend);

Can you perform file uploads using AJAX requests alone?
Yes, but only when using newer browsers and HTML5 features.

What is the syntax for the event listener that monitors whether the XMLHttpRequest object’s readyState attribute has changed?
onreadystatechange
Most JavaScript libraries that provide AJAX support include this header in AJAX requests by default.
X-Requested-With: XMLHttpRequest
True or false? Ajax can be used to open a connection from the server to the browser without the browser making an explicit request.
False

What does JSON do?
A data serialization and interchange format using a subset of JavaScript syntax
True or false? A GET request submitted through Ajax can never cause the server to delete data.
False
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);
The onreadystatechange change event is used to invoke behavior when
the status of the asynchronous request changes.

What is the preferred method for maintaining back/forward button and crawler functionality in Ajax-driven web applications?
history.pushState()

What is the difference between the XMLHttpRequest object’s .status and .statusText attributes?
.status returns a numeric-only code instead of the full HTTP response, which can be found in .statusText

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.
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 = new XMLHttpRequest();
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
What does the acronym “blob” stand for when referring to data types?
binary large object
Is it possible to add custom HTTP header to ajax request?
Yes, it is possible. setRequestHeader() method of XMLHttpRequest object can be used to add a custom HTTP header
Which method on the XMLHttpRequest object is used to send custom HTTP headers with a request?
setRequestHeader
In standard JavaScript, what makes asynchronous execution of Ajax calls possible?
Events and callbacks
What are the advantages of using JavaScript libraries (like jQuery) to implement Ajax?
Better cross-browser compatibility and faster speed of development
The primary benefit of using AJAX techniques in a web application is:
It allows web applications to send asynchronous data requests to a server without a user initiated page load.
Which browser features and/or technologies must be enabled, at a minimum, for AJAX techniques to function properly?
JavaScript must be enabled.
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.
200
How do you manually abort an Ajax request after a certain amount of time?
Using setTimeout(), clearTimeout() and .abort()
What is the purpose of Ajax long-polling?
To keep a server connection open for two-way communication
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?
200
How response will be parsed if responseType is set to “document” and the request has been made asynchronously?
as a text/html stream
Can an XMLHttpRequest object be used to receive binary data?
Yes, in newer browsers using the responseType property and in older browsers by overriding the mime type of the response.
Ajax can be used to open a connection from the server to the browser without the browser making an explicit request.
False
What is XSS?
Malicious client-side code injection
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);
This code is polling a timer rather using the onreadystatechange event to check the state of the async request.

How can you load JavaScript from a different file into your web application?
All of these

Which of the HTTP actions is an Ajax XML HTTP request capable of sending to a server?
GET, POST, PUT, and DELETE
What is the name of the object which provides CORS support in Internet Explorer 8 and Internet Explorer 9?
XDomainRequest
What does CORS stand for?
Cross-origin resource sharing
What is the CORS-enabled Ajax request object constructor in IE8-9?
new XDomainRequest();
When your Ajax request is complete, what attribute of the XML HTTP request object contains the returned data?
responseText
After a request completes, which property of the XMLHttpRequest object can be used to retrieve a DOM representation of a remote XML document?
responseXML
How would you configure a *synchronous* GET request to “/resource” after instantiating a new XMLHttpRequest object: var xhr = new XMLHttpRequest();?
xhr.open(“GET”, “/resource”, false);
According to the W3C specification, which HTTP methods should throw a security exception when used with XMLHttpRequest?
CONNECT, TRACE, or TRACK
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?
3
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-live
Which of these is NOT an advantage of using Ajax over server-side processing?
Cross-browser compatibility
What is the proper way to execute a callback function while making a “synchronous” request?
Callback functions are used with “asynchronous” requests only
How does Google recommend you make an Ajax-dependent page accessible to their web crawler?
Use Ajax to progressively enhance server-side processing, rather than to replace it
When receiving an image from the server, the responseType attribute of your XMLHttpRequest object must be set to:
“arraybuffer” or “blob”
What HTTP response header is expected in reply to a CORS request?
Access-Control-Allow-Origin
What happens if an Ajax call completes (and calls its callback function) when other JavaScript is currently running?
The Ajax callback function will be queued until the currently-running code completes
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?
Your request was canceled either due to a failed connection or a user action.
What is the value of the response property of XMLHttpRequest object if readyState property equal to 3?
null
What XMLHttpRequest method is used to override MIME type returned by the server?
overrideMimeType()
How do you detect errors in Ajax REQUESTS?
the onerror event
Ajax is frequently expanded as “asynchronous JavaScript and XML,” which is misleading. Which of these words is not central to Ajax’s functionality?
asynchronous and XML
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.
What arguments MUST be supplied to an XMLHttpRequest object’s .open() method, and in what order?
HTTP method as string, URL as string
How does JSONP work?
It makes server response text act like an injected <script> element
In non-IE browsers, what attribute should you check your XMLHttpRequest object for in order to see if it supports CORS?
withCredentials

No comments:

Post a Comment

Alternative content