简体   繁体   中英

Escape String equal special characters in JavaScript

I have a string in JavaScript:

ghi chú đặc biệt (!@#$%^&*) ngày 06/11/2018

How can I escape this and parse in URL Decode this in Java? I try using:

encodeURIComponent(url);

But I just get this String: ghi chú đặc biệt (!@ How can I fix it Thanks

Should be straightforward

 var uri = "ghi chú đặc biệt (!@#$%^&*) ngày 06/11/2018"; var res = encodeURIComponent(uri); console.log (res) 

Refer - https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_encodeuricomponent

You can use encodeURIComponent() and decodeURIComponent() to encode and then decode a url;

 var url="ghi chú đặc biệt (!@#$%^&*) ngày 06/11/2018"; var encoded = encodeURIComponent(url); var decoded = decodeURIComponent(encoded) console.log(`Encoded url ${encoded}`); console.log(`Decoded url ${decoded}`); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM