get : GET 방식으로 서버와 통신하는 jQuery Ajax 함수이다.
URL로 지정한 파일을 로드해서 그 데이터를 텍스트 형식으로 콜백 함수(fn)에게 넘겨주는 기능을 한다.
매개 변수
url : 요청할 서버 측 자원의
URL fn : 요청이 성공했을 때 호출할 콜백 함수
예제
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src = "../js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$.get('item.xml', function(data){
$('#fruitTable').append("<tr>" +
"<th>id</th>"+
"<th>name</th>" +
"<th>price</th>"+
"<th>description</th>"+
"</tr>");
$(data).find('item').each(function(){
$('#fruitTable').append("<tr>" +
"<td>"+ $(this).attr('id') +"</td>"+ //속성
"<td>"+ $(this).attr('name') +"</td>" + //속성
"<td>"+ $(this).children('price').text() +"</td>"+ //자신
"<td>"+ $(this).find('description').text() +"</td>"+ //자손
"</tr>" );
})
});
});
</script>
</head>
<body>
<h3>과일의 특성 조사 자료</h3>
<table id="fruitTable" border="1">
</table>
</body>
</html>
실행결과
'JQuery' 카테고리의 다른 글
[jQuery] 도서 정보 입력 (0) | 2023.09.22 |
---|---|
[jQuery] getJSON (0) | 2023.09.22 |
[jQuery] AJAX (0) | 2023.09.22 |
[jQuery] load (0) | 2023.09.22 |
[jQuery] 회원정보 입력 (0) | 2023.09.22 |