2013-05-16 12 views
5

Cercando di porta un frammento di codice da Python:urllib.quote_plus() equivalente in JavaScript

my_input = "this&is£some text" 
encoded_input = urllib.quote_plus(str(my_input)) 

... a JavaScript:

var my_input = "this&is£some text"; 
encoded_input = encodeURIComponent(my_input); 

La differenza minore è che urllib.quote_plus() convertirà spazi a + anziché %20(link). Basta chiedersi se qualcuno potrebbe fornire qualche idea. Attualmente andando con questo ...

var my_input = "this&is£some text"; 
encoded_input = encodeURIComponent(my_input).replace(/%20/g,'+'); 

risposta