我有這樣的代碼:如何使用JavaScript將字符串中的'更改爲%27?
var data = "I'm trying to send this with AJAX properly.";
data = encodeURIComponent(data);
data.replace("'", "%27");
data.replace(/'/, "%27");
alert(data); //Still not changed here...
我想送與AJAX到數據庫。但是'導致它根本不發送。 encodeURIComponent不會將'更改爲其代碼%27,data.replace也不會更改。
我在這裏做錯了什麼?
天哪,這是我的愚蠢......非常感謝! –
+1,用於快速,準確的響應。 :) – JAAulde
請注意,此方法將只替換第一次出現 –