1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<html>
<head>
<script language="javascript" src="../jquery/jquery-1.8.2.min.js"></script>
<script language="javascript">
// The API is passed a customer ID and the name of the return function
function showCustomer()
{
customerID = "haakon";
$.ajax({
type: 'POST',
url: '../booking/getcustomer_XML.php',
data: { customerID: escape(customerID)},
success: ResultCustomer
});
}
function ResultCustomer(returnedData)
{
// An XML DOM document is returned from AJAX
var resultset=returnedData.childNodes[0];
// Iterate over all nodes in root node (i.e. customers)
for (i = 0; i < resultset.childNodes.length; i++) {
// Iterate over all child nodes of that node that are customer nodes
if(resultset.childNodes.item(i).nodeName=="customer"){
// Retrieve first name and last name for node
var customer=resultset.childNodes.item(i);
alert(customer.attributes['firstname'].nodeValue+' '+customer.attributes['lastname'].nodeValue);
}
}
}
</script>
</head>
<body onload='showCustomer();'>
Showing alert with information about customer with customerID: haakon
</body>
</html>
|