본문 바로가기

프로그램 강좌

[javascript]이스케이핑 encodeURIComponent()

웹에서 데이터 전송시 특정 문자들은 특수기능으로 사용되는데, 해당특수문자들은 그대로 전송하면 시스템이 인식할 수 없게 됩니다. 그래서 이렇게 치환해줍니다.

const url = 'http://www.kakao.com';
const url2 = '?id=한글';

console.log(url+url2); //"http://www.kakao.com?id=한글"
console.log(url+encodeURIComponent(url2)); // "http://www.kakao.com%3Fid%3D%ED%95%9C%EA%B8%80"

 

728x90