- success: function( xmlResponse ) {
- var data = $( "name", xmlResponse ).map(function() {
- return {
- value: $( "firstName", this ).text();
- };
- }).get();
- }
Line 1: in response to the
success event, invoke this function with the parameter
xmlResponse.
Line 2: Within
xmlResponse, find elements with the tag name
name - which returns a jQuery collection of matching elements. Send these through the
map function.
Line 3-5: The
map function replaces each item in the collection with the function's return value, in this case the
text content of the
firstName element within
this (the current
name element).
Line 6: Convert the jQuery collection, that now consists of the
firstName elements' text content, into a regular JavaScript array, which is assigned to the variable
data.