개발모음집

fetch query 보내는 법 본문

client

fetch query 보내는 법

void 2020. 7. 6. 10:00
let params = {
  "param1": "value1",
  "param2": "value2"
};

let query = Object.keys(params)
             .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
             .join('&');

let url = 'https://example.com/search?' + query;

fetch(url)
  .then(data => data.text())
  .then((text) => {
    console.log('request succeeded with JSON response', text)
  }).catch(function (error) {
    console.log('request failed', error)
  });

출처 : https://stackoverflow.com/questions/35038857/setting-query-string-using-fetch-get-request