Ajax (Asynchronous Javascript And XML)

๋น„๋™๊ธฐ์ ์ธ ์›น ์ œ์ž‘์„ ์œ„ํ•ด ๊ธฐ์ˆ ๋“ค์˜ ์กฐํ•ฉ์„ ์ด์šฉํ•˜๋Š” ์›น๊ฐœ๋ฐœ ๊ธฐ๋ฒ•.

techs

  • HTML & CSS

    • DOM & JavaScript

    • XML & XSLT ( XML ๋ฌธ์„œ๋ฅผ ๋‹ค๋ฅธ XML ๋ฌธ์„œ๋กœ ๋ณ€ํ™˜ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” XML ๊ธฐ๋ฐ˜ ์–ธ์–ด /

      ์›๋ณธ XML ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒˆ๋กœ์šด XML ์ƒ์„ฑ ) & XHR => ์›น ์„œ๋ฒ„์™€ ๋น„๋™๊ธฐ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ตํ™˜ํ•˜๊ณ  ์กฐ์ž‘ํ•จ

  • cdn

    • vue js cdn ๊ฒ€์ƒ‰ - ๋ณต์‚ฌ ํ›„ ๊ธฐ์ž…

  • scrollmonitor

    <script src="<https://cdnjs.cloudflare.com/ajax/libs/scrollmonitor/1.2.0/scrollMonitor.js>" ></script>
  • Axios

    Promise ๊ธฐ๋ฐ˜ HTTP ํ†ต์‹  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. ๋ฌธ์„œํ™”๊ฐ€ ์ž˜๋˜์–ด ์žˆ๊ณ  API๊ฐ€ ๋‹ค์–‘ํ•จ.

    <script src="<https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js>"></script>
    <div id="app">
      <button v-on:click="fetchData">get data</button>
    </div>
    new Vue({
      el: '#app',
      methods: {
        fetchData: function() {
          axios.get('<https://jsonplaceholder.typicode.com/users/>')
            .then(function(response) {
              console.log(response);
            })
            .catch(function(error) {
              console.log(error);
            });
        }
      }
    })

    axios.get์—์„œ then์˜ ์ฝœ๋ฐฑํ•จ์ˆ˜์˜ ์ธ์ž๋Š” getํ•ด์„œ ์–ป์–ด์˜จ ๊ฒƒ์ด ๋“ค์–ด๊ฐ„๋‹ค.

  • Promise => ์„ฑ๊ณต/์‹คํŒจ

    ๋‹น์žฅ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๊ณผ "์•„๋‹Œ ๊ฒƒ"

    • ๋ถˆํ™•์‹คํ•˜๊ณ  ๊ธฐ๋‹ค๋ ค์•ผํ•˜๋Š” ์ž‘์—…(AJAX, axios)์„ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ + ๊ทธ๋Ÿฌํ•œ ์ž‘์—…๋งŒ์„ ์œ„ํ•จ

    • method: ์™ธ๋ถ€์š”์ฒญ(XHR), ๊ธฐ๋‹ค๋ฆฌ๋Š” ๊ฒƒ(settimeout)

  • ex of ๋น„๋™๊ธฐ์  ์ฒ˜๋ฆฌ

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <script>
            const xhr = new XMLHttpRequest()
            xhr.open('GET', 'https: koreanjs~~~')
            xhr.send() //์•„์ง ๋๋‚˜์ง€ ์•Š
    
            const res = xhr.response
            console.log('RES:', res)
    
        </script>
    </body>
    </html>
    > xhr.response
    < "{"id":1, "title": "์ •๋‹น์˜ ๋ชฉ์ ์ด๋‚˜ ~~~"}"
    
    > res === ""
    < true

    : ํŒŒ์ด์ฌ์€ ์ธํ„ฐํ”„๋ฆฌํ„ฐ์–ธ์–ด๋กœ ๋ธ”๋Ÿญํ‚นํ•˜๋ฉด์„œ ๋„˜์–ด๊ฐ€๊ณ , JS๋„ ๊ทธ๋ ‡์ง€๋งŒ, DOM์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ช‡๋ช‡ ๋งค์„œ๋“œ๊ฐ€ ์ฝ”๋“œ ํ•˜๋‚˜ํ•˜๋‚˜ ์•ˆ ๊ธฐ๋‹ค๋ ค์ฃผ๊ณ  ๋„˜์–ด๊ฐ.

  • caution

    • ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ์“ด๋‹ค => non-blockingํ•œ ๋น„๋™๊ธฐ ์ž‘์—…ํ•œ๋‹ค (X)

    • non - blocking ํ•œ ๋น„๋™๊ธฐ ์ž‘์—…์„ ํ•œ๋‹ค. => ์ฝœ๋ฐฑ์„ ์“ธ ์ˆ˜ ๋ฐ–์— ์—†๋„๋ก ์„ค๊ณ„๋˜์–ด ์žˆ๋‹ค

  • XML (Extensible Markup Language)

    • ๊ตฌ์กฐ์ ์ธ ๋ฐ์ดํ„ฐ๋ฅผ ์œ„ํ•œ ๊ฒƒ์ด๋‹ค.

    • ๋‹ค์†Œ HTML ๊ฐ™์ด ๋ณด์ธ๋‹ค.

    • ํ…์ŠคํŠธ์ด๋ฉฐ, ์ฝํžˆ๋Š” ๊ฒƒ๋งŒ์„ ๋œปํ•˜์ง€ ์•Š๋Š”๋‹ค.

    • ํฌ๊ธฐ๊ฐ€ ์ปค์ง„๋‹ค.

    • ๊ธฐ์ˆ ์˜ ์ง‘ํ•ฉ์ด๋‹ค.

    • ์ƒˆ๋กœ์šด ๊ธฐ์ˆ ์ด ์•„๋‹ˆ๋ผ ๋ฐœ์ „ํ•œ ๊ธฐ์ˆ ์ด๋‹ค.

    • HTML์—์„œ XHTML๋กœ ์ด๋Œ์—ˆ๋‹ค.

    • ๋ชจ๋“ˆ์‹์ด๋‹ค.

    • RDF์™€ ์‹œ๋งจํ‹ฑ ์›น์˜ ํ† ๋Œ€์ด๋‹ค.

    • ๋ผ์ด์„ ์Šค ์ œ์•ฝ์ด ์—†์œผ๋ฉฐ, ํ”Œ๋žซํผ์ด ๋…๋ฆฝ์ ์ด๊ณ , ๋งŽ์€ ์ง€์›์ด ์žˆ๋‹ค.

  • XHR (XMLHttp request)

    ๋ธŒ๋ผ์šฐ์ €์™€ ์„œ๋ฒ„ ๊ฐ„ "๋ฉ”์†Œ๋“œ๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†ก"ํ•˜๋Š” "๊ฐ์ฒด ํ˜•ํƒœ์˜" API

    Ajax ๋ฅผ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š”๊ฑด XHR๋ฐ–์— ์—†๋Š”๋ฐ, ์˜ˆ๋ฅผ ์‰ฝ๊ฒŒ ์“ธ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” axios

    • ex) ์ž๋™์™„์„ฑ

MVVM ํŒจํ„ด

ex) ํŽ˜๋ถ์ด๋‚˜ ๊ตฌ๊ธ€๋งต์—์„œ ํ•œ ํŽ˜์ด์ง€ ์•ˆ์—์„œ ์š”์ฒญ์ด ์ผ์–ด๋‚จ.

JS๋Š” ์ž‘์—…ํ™˜๊ฒฝ์ธ Document(tab)์ด ์‹ฑ๊ธ€์Šค๋ ˆ๋“œ์ด๊ธฐ ๋•Œ๋ฌธ์—, ๋น„๋™๊ธฐ(์–ด๋–ค ์ž‘์—…์„์ด ์ข…๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ , ๋‹ค๋ฅธ ์ž‘์—…์„ ํ•˜๊ณ  ์žˆ๋‹ค๊ฐ€, ์š”์ฒญํ•œ ์ž‘์—…์ด ์ข…๋ฃŒ๋˜๋ฉด, ๊ทธ์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์ž‘์—…์„ ์ด์–ด์„œ ์ˆ˜ํ–‰) ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค.

Last updated