dongtigai3875 2016-08-14 07:12
浏览 20
已采纳

在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
$.ajax({
    type: "POST",
    data:dataString,
    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

  • 写回答

1条回答 默认 最新

  • dongzha3058 2016-08-14 07:18
    关注

    You can try this:

    var message = encodeURIComponent('I like cricket & football');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?