A Simple Document Phase Example of Active Client Pages
The Store Segment
These are the statements for the store segment:
var firstName = "John";
var lastName = "Smith";
The Ajax Code Segment
This is the longest of the three sub code segments. It is not long because it has a lot of executing statements; it is long because we use different, alternative ways to address different browsers. Each one is particular to a browser or set of browsers. This is the code segment:
You have the page2Doc string variable. This variable will hold the downloaded text to be used to develop and load the second page. Next you have the xmlHttp variable; this variable will hold the XMLHttpRequest object. Next you have an “integrated” try…catch statement. We have seen this before. This statement is long because of the different ways of addressing different browsers. It is this statement that makes the Ajax code segment long.
Next you have the function that will assign the downloaded text to the page2Doc variable. This function is defined and at the same time assigned to the onreadystatechange variable, which is a property of the XMLHttpRequest object. Each time there is a change in the status of the request, this function is called, because it has been assigned to the onreadystatechange property. All these are taken care of by the XMLHttpRequest object. The responseText in the code is also a property of the XMLHttpRequest object.
You command the download next in the Ajax code segment. Two statements are used here. The first one has the URL of the executable file (sendPge2Str.pl) at the server, which will send the text in string form. The second statement must accompany the first. We have seen these statements before.