61장 JQueryAjax XML파일 로드하기 (get)
- 버튼 클릭시 이벤트 처리 get.html |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XML 파일 로드하기</title> <script src="../../jquery-1[1].3.2-vsdoc2.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $("#btn").click(function () { $.get('04장a.Company.xml', function (data){ $('#ctlGrid').empty(); $(data).find('Company').each(function (){ var $entry = $(this); //특성Attribute)을 읽어오기 //하위 엘리먼트 읽어오기 $('#ctlGrid').append($(html)); }); }); }); }); </script> </head> <body> <input type="button" id="btn" value="회사소개" /> <div id="ctlGrid"></div> </body> </html> |
Company.XML |
<?xml version="1.0" encoding="utf-8" ?> <Company CompanyTye="Private"> <CompanyName>용원이 블로그</CompanyName> <CompanyNumber>1234</CompanyNumber> <CompanyAddress>서울</CompanyAddress> <CompanyAddressDetail>세울</CompanyAddressDetail> <Name>김용원</Name> </Company> |