There is a standard select , which will be the choice of dealers. There is an xml file with data for these dealers. How to connect this file to select ?
1 answer
Example xml file:
<?xml version='1.0'?> <DealersInfo> <Dealer> <Title>name 1</Title> </Dealer> <Dealer> <Title>name 2</Title> </Dealer> <Dealer> <Title>name 3</Title> </Dealer> </DealersInfo> Html:
<select name="test" id="test_select"> <option>Выберите диллера</option> </select> Jquery:
$.ajax({ type: "GET", url: "test.xml", //ваш xml файл dataType: "text", success: function(xml) { var xmlDoc = $.parseXML(xml), $xml = $(xmlDoc); $xml.find('Dealer').each(function() { //test_select - id селекта $('<option>').text($(this).find('Title').text()).appendTo($('#test_select')); /* или(способ 2) $("#test_select").append('<option>$(this).find('Title').text()</option>'); или(способ 3, более медленный) $('#test_select').append($('<option>', { value: $(this).find('Title').text(), // или поставьте свое значение value text : $(this).find('Title').text() })); */ }); } }); |