- #exec_json() : XE에서 Ajax 요청(Request)을 하는 자바스크립트 함수(정보 변경 또는 정보 조회)XE - exec_json() : XE에서 Ajax 요청(Request)을 하는 자바스크립트 함수(정보 변경 또는 정보 조회) (googleusercontent.com)2025년 02월 03일
- TheStorybook
- 작성자
- 2025.02.03.:48
exec_json() : XE에서 Ajax 요청(Request)을 하는 자바스크립트 함수(정보 변경 또는 정보 조회)
XE_ROOT/common/xml_handler.js에 선언되어 있습니다.
exec_json() 함수는 XE에서 ajax기능을 이용함에 있어 module, act를 잘 사용하기 위한 자바스크립트
exec_xml 보다 exec_json을 추천.
exec_xml에서 특정 데이터를 받아올 때 오류가 나지만 exec_json은 그렇지 않다. 또한 exec_json이 사용법이 더 간단하다.exec_json (module.act, params, callback_func ); module.act : 모듈명.action ( exec_json()은 자바스크립트 내부에서 요청만 할 뿐 실제적인 일은 해당 모듈의 액션(act)을 호출하여 처리 결과를 받는다.) params : 전달할 변수 json 형식 callback_func : javascript callback 함수 (응답으로 받은 데이터를 처리할 자바스크립트 함수에게 값을 넘겨주는 함수 , javascript callback 함수 첫번째 인수에 모듈에서 $this->add로 보낸 변수를 받음)
<script type="text/javascript"> function moveVar(type, module_srl, var_idx) { // 전달할 변수 json 형식 var params = { type : type, module_srl : module_srl, var_idx : var_idx }; exec_json('document.procDocumentAdminMoveExtraVar', params, function() { location.reload() }); // 실행 } </script> 그런다음 해당 버튼을 클릭 위 또는 아래로 해서 순서 변경을 하게 됩니다. <button type="button" class="x_icon-arrow-up" onclick="moveVar('up','123','3')" title=" 위로 ">위로</button> <button type="button" class="x_icon-arrow-down" onclick="moveVar('down','123','3')" title=" 아래로 ">아래로</button>
이번에는 exec_json()를 이용 해서 특정 게시물 데이타를 출력하는 스크립트 예제입니다.
<script type="text/javascript"> // 게시물 조회 function doSelectDocView(document_srl) { var params = { mid : 'board', document_srl : document_srl }; exec_json('board.dispBoardContentView', params, completeDocView); } // 조회 후 출력 // javascript callback 함수 첫번째 인수에 모듈에서 $this->add로 보낸 변수를 받음 function completeDocView(ret_obj) { var error = ret_obj.error; var message = ret_obj.message; var oDocument = ret_obj.oDocument; if(message != 'success') { // 실패시 alert(message); } var tmp_msg = ""; // 게시물 제목 tmp_msg += "게시판 제목 : "+oDocument.title; // 게시물 제목 tmp_msg += "<br /><br />게시물 내용<br />"; // 게시물 제목 tmp_msg += oDocument.content; // 게시물 내용 document.getElementById("dovView").innerHTML = tmp_msg; } doSelectDocView(331); </script> <div id="dovView"></div><!--// 게시물 내용을 출력할 부분 -->
exec_json()를 이용한 doSelectDocView 스크립트를 이용하여 외부페이지에 게시물 데이타를 불러온 화면
참고로 XE_ROOT/common/xml_handler.js에 선언되어 있는 exec_json 스크립트 내용입니다.
/** * @brief exec_json (exec_xml와 같은 용도) **/ $.exec_json = window.exec_json = function(action, data, callback_sucess, callback_error){ if(typeof(data) == 'undefined') data = {}; action = action.split('.'); if(action.length == 2) { // The cover can be disturbing if it consistently blinks (because ajax call usually takes very short time). So make it invisible for the 1st 0.5 sec and then make it visible. var timeoutId = $(".wfsr").data('timeout_id'); if(timeoutId) clearTimeout(timeoutId); $(".wfsr").css('opacity', 0.0); $(".wfsr").data('timeout_id', setTimeout(function(){ $(".wfsr").css('opacity', ''); }, 1000)); if(show_waiting_message) $(".wfsr").html(waiting_message).show(); $.extend(data,{module:action[0],act:action[1]}); if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid}); try { $.ajax({ type: "POST", dataType: "json", url: request_uri, contentType: "application/json", data: $.param(data), success: function(data) { $(".wfsr").hide().trigger('cancel_confirm'); if(data.error != '0' && data.error > -1000) { if(data.error == -1 && data.message == 'msg_is_not_administrator') { alert('You are not logged in as an administrator'); if($.isFunction(callback_error)) callback_error(data); return; } else { alert(data.message); if($.isFunction(callback_error)) callback_error(data); return; } } if($.isFunction(callback_sucess)) callback_sucess(data); }, error: function(xhr, textStatus) { $(".wfsr").hide(); var msg = ''; if (textStatus == 'parsererror') { msg = 'The result is not valid JSON :\n-------------------------------------\n'; if(xhr.responseText === "") return; msg += xhr.responseText.replace(/<[^>]+>/g, ''); } else { msg = textStatus; } try{ console.log(msg); } catch(ee){} } }); } catch(e) { alert(e); return; } } };
다음글이전글이전 글이 없습니다.댓글
스킨 업데이트 안내
현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)