[PHP + AXIOS] Get / Post > Js/Server/Package

본문 바로가기
사이트 내 전체검색

Js/Server/Package

[PHP + AXIOS] Get / Post

페이지 정보

작성자 sbLAB 댓글 0건 조회 1,324회 작성일 23-07-09 19:21

본문

axios/axios ★

https://github.com/axios/axios#cdn



AXIOS + GET request (params)



   <head>
   </head>

   <body>
   <div>
      <input type="text" placeholder="토큰입력" id="tk" value="" size="70" />
   </div>
   <input type="button" onclick="onLoggin()" value="Request" />

   <script>
      let onLoggin = async function () {
         const tk = document.getElementById('tk');

         try {
            // axios 요청 (get)
            let res = await axios({
               method: 'GET',
               url: 'http://server_url/all',
               params: {
                  tk: tk.value,
               },
            });

            console.log(res);
            console.log(res.data);
            console.log(res.data[0]);
            console.log(res.status);
            document.getElementById('list_here').innerHTML = JSON.stringify(res);
            //document.write(JSON.stringify(res));
         } catch (err) {
            console.log(err);
            throw new Error(err);
         }
      };
   </script>
   </body>
   <div id="list_here"></div>

 



AXIOS + POST request (data)



    <head>
    </head>

    <body>
    <div>
        <input type="text" placeholder="토큰입력" id="tk" value="" size="70" />
    </div>
    <input type="button" onclick="onLoggin()" value="Request" />

    <script>
        let onLoggin = async function () {
            const tk = document.getElementById('tk');

            try {
            // axios 요청 (post)
            let res = await axios({
                method: 'POST',
               url: 'http://server_url/add',
                data: {
                    tk:'...........token value................'
                },
            });

            console.log(res);
            console.log(res.data);
            console.log(res.data[0]);
            console.log(res.status);

            document.getElementById('list_here').innerHTML = JSON.stringify(res);
            //document.write(JSON.stringify(res));
            } catch (err) {
            console.log(err);
            throw new Error(err);
            }
        };
    </script>
    </body>
    <div id="list_here"></div>


 





댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
231
어제
401
최대
1,279
전체
221,885

그누보드5
Copyright © sebom.com All rights reserved.