반응형
$.ajax({
type: "POST",//전송방식 GET,POST
url: "전송할 페이지 URL",
data: {name : "value" , name2 : "value2"},//파라미터 전송
dataType: "xml",//페이지 리턴 형식 json, jsonp, xml, html
async: false, //동기식 = false , 비동기식 = true // 기본값 true
success: function(xml){ //아작스 전송 성공시 실행 스크립트
//$("#contents").html(xml);
},
beforeSend : function(){// 아작스 전송전 실행 스크립트
$("#nation_content_view").showLoading();
},
complete : function(){//아작스 작업 완료후 실행 스크립트
$("#nation_content_view").hideLoading();
},
error: function(xhr, status, error){ // 아작스 에러 발생시 실행 스크립트
alert("에러 : " + error);
}
});
type: "POST",//전송방식 GET,POST
url: "전송할 페이지 URL",
data: {name : "value" , name2 : "value2"},//파라미터 전송
dataType: "xml",//페이지 리턴 형식 json, jsonp, xml, html
async: false, //동기식 = false , 비동기식 = true // 기본값 true
success: function(xml){ //아작스 전송 성공시 실행 스크립트
//$("#contents").html(xml);
},
beforeSend : function(){// 아작스 전송전 실행 스크립트
$("#nation_content_view").showLoading();
},
complete : function(){//아작스 작업 완료후 실행 스크립트
$("#nation_content_view").hideLoading();
},
error: function(xhr, status, error){ // 아작스 에러 발생시 실행 스크립트
alert("에러 : " + error);
}
});
jQuery 아작스 틀
그중 success 부분을 아래와 같이 처리
if( $(xml).find("result_size").text() > 0 ){
//반복문으로 파일 표시
$(xml).find("record").each(function(){
var path = $(this).find("PATH").text();
var name = $(this).find("NAME").text();
var view = $(this).find("VIEW").text();
});
}
//반복문으로 파일 표시
$(xml).find("record").each(function(){
var path = $(this).find("PATH").text();
var name = $(this).find("NAME").text();
var view = $(this).find("VIEW").text();
});
}
리턴 xml 양식
<result_set>
<success>true</success>
<result_size>3</result_size>
<record no="1">
<PATH>파일경로</PATH>
<NAME>파일명칭</NAME>
<VIEW>뷰 어쩌고 저쪼고</VIEW>
</record>
<record no="2">
<PATH>파일경로</PATH>
<NAME>파일명칭</NAME>
<VIEW>뷰 어쩌고 저쪼고</VIEW>
</record>
<record no="3">
<PATH>파일경로</PATH>
<NAME>파일명칭</NAME>
<VIEW>뷰 어쩌고 저쪼고</VIEW>
</record>
</result_set>
<success>true</success>
<result_size>3</result_size>
<record no="1">
<PATH>파일경로</PATH>
<NAME>파일명칭</NAME>
<VIEW>뷰 어쩌고 저쪼고</VIEW>
</record>
<record no="2">
<PATH>파일경로</PATH>
<NAME>파일명칭</NAME>
<VIEW>뷰 어쩌고 저쪼고</VIEW>
</record>
<record no="3">
<PATH>파일경로</PATH>
<NAME>파일명칭</NAME>
<VIEW>뷰 어쩌고 저쪼고</VIEW>
</record>
</result_set>
반응형
'공부거리 > AJAX' 카테고리의 다른 글
[JQUERY]jquery 를 사용한 아작스 (0) | 2015.12.22 |
---|---|
XMLHttpRequest 방식 Ajax 통신 (0) | 2013.04.18 |