20231006 - AJAX 에러 핸들링 with PL/SQL JSON 결과 리턴

PL/SQL :


  if l_sid_om != l_sid_m then
    apex_json.open_object;
    apex_json.write('error', true);
    apex_json.write('code', 'ECD-1');
    apex_json.close_object;
    return;
  end if;

  apex_json.open_object;
  apex_json.write('success', true);
  apex_json.write('message', '담기 성공!');
  apex_json.close_object;



Javascript :


apex.server.process('AJAX-ADDtoCART2', {
  x01: selectedMODIDs,
  x02: buttonQty,
  x03: initialPrice,
  pageItems: "#P13_SID,#P13_MID,#P13_MNM,#P13_UMID"
}, {
  success: function(data) {
    apex.message.showPageSuccess(data.message);
    setTimeout(function() {
      OnClickBack();
    }, 1000);
  },
  error: function(xhr, status, error) {
    var JSONCD = xhr.responseJSON.code;
    var vTitle, vText;
    if (JSONCD == "ECD-1") {
        vTitle = "매장확인필요";
        vText  = "장바구니에 저장된 메뉴의 매장과 추가로 담으려는 매장이 다릅니다. 다른 매장의 메뉴와 같이 주문할 수 없습니다.";
    }

    apex.message.alert(vText, function(){
    }, {
        title: vTitle,
        style: "warning"
    } );
  }  
});






참고
https://docs.oracle.com/en/database/oracle/apex/23.1/aexjs/apex.server.html#.process
https://docs.oracle.com/en/database/oracle/apex/23.1/aexjs/apex.message.html#.showErrors

댓글 없음:

댓글 쓰기

20250202 - IG 다운로드 버튼 바로 보이기

JS initialization Code : function (config) {     var $ = apex.jQuery,         toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),  ...