TUTORIAL 3 Ajax and XMLHttpRequest

Document Sample
scope of work template
					SECC402: Rich Internet Applications

TUTORIAL 3: Ajax and XMLHttpRequest

Question 1
Use DOM documentation to answer the following:

   (a) What method of the XMLHttpRequest object would you use to display all the
       HTTP response headers?
   (b) What property of the XMLHttpRequest object would you use to get the response
       content in the form of an XML document?
   (c) Name one property of the XMLHttpRequest object which is only available in
       Internet Explorer and one method which is only available in Firefox.

You can find documentation at the following locations:

Question 2
What, according to Jesse James Garrett, are the biggest challenges in creating Ajax

Question 3
Explain the difference between an asynchronous HTTP request and a synchronous

Question 4
Describe the components of Ajax and the role that each component plays.

Question 5
Explain the role of onreadystatechange and readystate in handling asynchronous

                                                                    please turn over

                                         page 1
SECC402: Rich Internet Applications

Question 6
In the code example below, the function sendAsyncRequest is called by the body onload

textfile.txt contains a single line of text (Hello there!).

Write down the output you would expect when the page loads.

var req;
var output = "";

function sendAsyncRequest()
     var url = "textfile.txt";
     req = new XMLHttpRequest();
     req.open("GET", url, true);
     req.onreadystatechange = sendAsyncRequestCallBack;

function sendAsyncRequestCallBack()
     output += "readyState=" + req.readyState + "<br/>";
     output += "response=" + req.responseText + "<br/>";
     if (req.readyState == 4) {
          if (req.status == 200) {
               output += "Ready now - status: " +
               req.statusText + "<br/>";

                                              page 2

How are you planning on using Docstoc?