jQuery Ajax - Iterate over XML
by Alvin Olavarrieta
HTML
<response>
<response_code>0</response_code>
<global_destinations>
<countryID>14</countryID>
<country_name>Argentina</country_name>
<destination_code>54</destination_code>
<destination_currency>USD</destination_currency>
<include_mobile>0</include_mobile>
<currency_symbol>$</currency_symbol>
<product_name>Cloud Call ($10)</product_name>
<dialingCode>54</dialingCode><isoCode>AR</isoCode>
<sort>999</sort>
<countryFlag>Argentina.png</countryFlag>
</global_destinations>
<global_destinations>
<countryID>20</countryID>
<country_name>Australia</country_name>
<destination_code>61</destination_code>
<destination_currency>USD</destination_currency>
<include_mobile>0</include_mobile>
<currency_symbol>$</currency_symbol>
<product_name>Cloud Call ($10)</product_name>
<dialingCode>61</dialingCode>
<isoCode>AU</isoCode>
<sort>999</sort>
<countryFlag>Australia.png</countryFlag>
</global_destinations>
</response>
JavaScript
$.ajax({
type: "POST",
async: false,
url: getProductList,
data: reqProductXML,
dataType: "xml",
contentType: "text/xml; charset=\"utf-8\"",
success: function (data) {
$(data).find('product').each(function () {
var productID = $(this).find('id').text();
var productName = $(this).find('name').text();
var productCurrency = $(this).find('currency').text();
var productDescription = $(this).find('description');
var sipAccess = $(this).find('sipAccess');
var skypeAccess = $(this).find('skypeAccess');
var localAccess = $(this).find('localAccess');
var rechargeable = $(this).find('rechargeable').text();
});
}
});//End ajax