본문 바로가기

study/Front

axios.js

let tmpDt = "empty";
    fn_get_corp_cd=function(){
    axios({
       method: 'get', //통신 방식
       url: '/logs/getCORP_CD', //통신할 페이지
       data: {} //인자로 보낼 데이터
    })
    .then(response=>{
       console.log('console responseData',response);
       tmpDt = response;
       return tmpDt;
    })
    .catch(error=>{
       //console.log(error);
       tmpDt = error;
       return tmpDt;

    })


    $("#corpcdselect").empty();
    $("#corpcdselect").append(htm)


}
function resolveAfter2Seconds() {
    return new Promise((resolve) => {
       setTimeout(() => {
          resolve(tmpDt);
       }, 2000);
    });
}

async function asyncCall() {
    console.log('calling');
    const result = await axios.post('/logs/getCORP_CD').then(response=>{
          console.log(response)
          });

    console.log("result2 ",result);
    const result2 = await axios.post('/logs/getCORP_CD').then(res=>{
       console.log(res)
    });

    // Expected output: "resolved"
}

 TestApiCall = async function(){
    try {
       const response = await axios.post('/logs/getCORP_CD')
       console.log("response >>", response.data)
       const response2 = await axios.post('/logs/getCORP_CD')
       console.log("response >>", response2.data)
    } catch(err) {
       console.log("Error >>", err);
    }
}

 

 

axios.js
0.06MB