I have this code:
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...
I want to send that with AJAX to the database. But the ‘ is causing it to not send at all.
encodeURIComponent doesn’t change the ‘ to its code %27, neither does data.replace.
What am I doing wrong here?
You’re not re-assigning
data.replace()returns the modified string, it doesn’t modify the calling object string directly.