[PHP + AXIOS] Get / Post > Unity

본문 바로가기

사이트 내 전체검색

Unity

[PHP + AXIOS] Get / Post

작성일 23-07-09 19:21

페이지 정보

작성자sbLAB 조회 1,366회 댓글 0건

본문

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>


 





댓글목록

등록된 댓글이 없습니다.

Copyright © 소유하신 도메인. All rights reserved.
PC 버전으로 보기