Kentgi Tomo Kentgi Tomo - 15 days ago 5
Javascript Question

javascript comma doesn't encoded

i want to encode this text from


2016, Odd Semester, Periode 1


to


2016%2C%20Odd%20Semester%2C%20Periode%201


but i can't encode the comma.

it show like this


2016,%20Odd%20Semester,%20Periode%201


here my code

var Term = '2016, Odd Semester, Periode 1'
encodeURI(Term);

Answer

Use encodeURIComponent():

var foo = encodeURIComponent('2016, Odd Semester, Periode 1');
console.log(foo);