In JavaScript or jQuery, how do you convert a single string with three words ("abc def hij") into an encoded url format: "abc + def + hij"?

I need to encode some lines to add to the url.

My line contains several words: "abc def hij"(i.e. not three separate lines, but one line with three words in it ).

In JavaScript or jQuery, how do you convert such a string ( "abc def hij") to an encoded format "abc+def+hij":?

+3
source share
1 answer

encodeURIComponent converts the string to percent encoding.

Besides,

/x -www-form-urlencoded (POST), http://www.w3.org/TR/html401/interac...m-content-type, '+', encodeURIComponent "%20" "+".

string.replace(/%20/g, "+");

.

+10

Source: https://habr.com/ru/post/1773226/


All Articles