Which line of code should you use?

Topic 2, Volume B

You are developing a web page that consumes a Windows Communication Foundation (WCF) service. The page includes the following code segment.

var xhr = new XMLHttpRequest() ;

The page uses the xhrHandler() method to listen for changes to the request status of the WCF service calls. It uses the xmlToJavaScript() method to convert the response from the WCF service to a JavaScript object.

The xhrHandler() method must be called automatically each time the request status changes.

You need to add the event handler to the request object.

Which line of code should you use?
A . xhr.onCallback = xhrHandler;
B . xhr.onreadystatechange = xhrHandler;
C . xhr.readyState = xhrHandler;
D . xhr.status = xhrHandler;

Answer: B

Explanation:

/ onreadystatechange: Sets or retrieves the event handler for asynchronous requests.

Specifies a reference to an event handler for an event that fires at every state change

readyState

Returns the state of the object as follows:

* 0 = uninitialized C open() has not yet been called.

* 1 = open C send() has not yet been called.

* 2 = sent C send() has been called, headers and status are available.

* 3 = receiving C Downloading, responseText holds partial data (although this functionality is not available in IE [3])

* 4 = loaded C Done.

/ Example (assuming that there is a function handler():

var oReq = getXMLHttpRequest();

if (oReq != null) {

oReq.open("GET", "http://localhost/test.xml", true);

oReq.onreadystatechange = handler;

oReq.send();

Reference: XMLHttpRequest object; XMLHttpRequest (XHR)

https://msdn.microsoft.com/en-us/library/ie/ms535874(v=vs.85).aspx

http://mrfwebdesign.blogspot.ca/2008/11/xmlhttprequest-xhr.html

Latest 70-480 Dumps Valid Version with 288 Q&As

Latest And Valid Q&A | Instant Download | Once Fail, Full Refund

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments