25.07.2014 Views

Analysis and Testing of Ajax-based Single-page Web Applications

Analysis and Testing of Ajax-based Single-page Web Applications

Analysis and Testing of Ajax-based Single-page Web Applications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure A.2 The run-time Document Object Model after the <strong>page</strong> is fully loaded into<br />

the browser (bottom) <strong>and</strong> the rendered user interface (top).<br />

A.3 Requesting Data<br />

What we would like to achieve is to get web content, not as whole <strong>page</strong>s but<br />

as fragments from the server, <strong>and</strong> update the <strong>page</strong> dynamically without a<br />

<strong>page</strong> refresh. To that end, we use JavaScript to access the XMLHttpRequest<br />

object <strong>and</strong> the run-time DOM-tree to achieve our goal.<br />

Figure A.3 presents the JavaScript code that is included in the HTML <strong>page</strong><br />

(see line 3 in Figure A.1). Our JavaScript code begins by instantiating a correct<br />

XMLHttpRequest object. Note that different browsers (e.g., IE, Firefox) have<br />

different implementations for this object. The loadFragment function shows<br />

how the XMLHttpRequest object can be used to transfer data between the<br />

browser/server. The method takes a number <strong>of</strong> parameters:<br />

method can have a value <strong>of</strong> GET or POST. A variety <strong>of</strong> other HTTP methods<br />

(W3C, b) are also possible.<br />

url may be either a relative or an absolute URL which points to a resource.<br />

164 A.3. Requesting Data

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!