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
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
params a string representing the request content. Used with the POST method<br />
to send form parameters to the server.<br />
target element id the ID <strong>of</strong> the DOM element where the response content should<br />
be injected into.<br />
callbackFunction h<strong>and</strong>les the response content.<br />
Using these parameters, the loadFragment function sends a request to the<br />
server <strong>and</strong> calls the callback function when a valid response is obtained from<br />
the server.<br />
The getData function is a wrapper function which calls the loadFragment<br />
function with the correct parameters.<br />
The getData function is attached to the onclick attribute <strong>of</strong> the clickable element,<br />
as can be seen in line 12 <strong>of</strong> Figure A.1. This function is called with two<br />
parameters, namely server.php as the URL, <strong>and</strong> container as the target element<br />
ID. This gives us the desired behavior that when the element is clicked<br />
by the user, the getData method is called, which in turn calls the loadFragment<br />
function to get data from the server.php URL on the server.<br />
A.4 The Server-side Code<br />
Figure A.4 show the contents <strong>of</strong> our server.php which simply returns the code<br />
for a HTML form.<br />
1 <br />
Figure A.4 server.php source code.<br />
A.5 DOM Injection<br />
Once the response <strong>of</strong> the server is successfully arrived at the browser, the<br />
callback function is called. The insertIntoDOMElement function takes the ID<br />
<strong>of</strong> the target element <strong>and</strong> the response data, as parameters. It uses the ID to<br />
find a reference to the corresponding run-time element in the DOM instance<br />
(line 28 in Figure A.3). Once a reference has been found, the response data is<br />
injected into the inner part <strong>of</strong> that element. As soon as the content is injected<br />
166 A.4. The Server-side Code