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
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
A.6 Submitting Data<br />
The new state contains a form which we use as a simple calculator. The user<br />
fills in the first <strong>and</strong> second digits along with one <strong>of</strong> the four supported operations<br />
for addition (add), subtraction (sub), multiplication (mul), <strong>and</strong> division<br />
(div). Upon clicking on the button labeled Calculate, an event is fired which<br />
calls the submitData JavaScript function (see lines 36–41 in Figure A.3), with<br />
calculate.php as URL <strong>and</strong> result as the target element ID. This function simply<br />
retrieves the input values filled in by the user on the form <strong>and</strong> calls the<br />
loadFragment function with relevant parameter, i.e., ‘POST’ as method, <strong>and</strong> the<br />
input values as params.<br />
Figure A.6 shows the server-side PHP code that is responsible for the calculation.<br />
Based on the value <strong>of</strong> the three request parameters (val1, val2, calc),<br />
a response in returned to the browser.<br />
1 <br />
Figure A.6 Server-side PHP calculator.<br />
The response is then injected into the DIV element with ID result. Figure A.7<br />
shows the request/response, focusing on the response returned by the server<br />
as a delta fragment. It also shows the updated browser user interface, in<br />
which the result <strong>of</strong> the calculation can be seen. Note that all the user interface<br />
updates have taken place on a single <strong>page</strong>. This is evident by the fact that the<br />
address-bar <strong>of</strong> the browser is still pointing to the same index HTML <strong>page</strong>.<br />
168 A.6. Submitting Data