Snehasish Sarker Snehasish Sarker - 5 months ago 40
PHP Question

Remove '&' sign from string automatically in JavaScript

I am sending a string through JavaScript, but the problem is that it removes the '&' sign automatically. Before the Ajax request I have got the string perfectly, but on the server side I don't get any '&' in the string.

var user = 1; // ex: user_id
var message = "I like cricket & football"; // Example: message
var dataString = "user"=+ user + "&msg=" + message;
alert(message); // It shows my string perfectly: I like cricket & football
type: "POST",
url: rootPath()+"user/reply_msg_user",
success: function(data){}

After sending the datastring by the Ajax request on the server side it only shows:

I like cricket football


You can try this:

var message = encodeURIComponent('I like cricket & football');