AJAX - The Complete Reference

(avery) #1

Chapter 3: XMLHttpRequest Object 75


PART I


noted at this point that the URL requested must be within the same domain, using the same
port and the same protocol from which a page is served. Browsers will deny other requests
as breaking the same-origin policy. More details can be found on this and other security
concerns in Chapter 7. Also note that a null value is sent in this particular example because
there is no data to submit in the message body. When using POST to send data later in this
chapter, that will not be the case. To keep things simple, the raw response is used and accessed
via the XHR’s responseText property and then added to the page using standard DOM
methods. To be precise, innerHTML actually a W3C-specified DOM property as of yet, but is
often assumed to be because of its ubiquitous support. The complete example is shown here
with a communication trace in Figure 3-2.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Chapter 3 : XMLHttpRequest - Synchronous Send</title>
<link rel="stylesheet" href="http://ajaxref.com/ch3/global.css"
type="text/css" media="screen" />

FIGURE 3-2 Simple synchronous request
Free download pdf