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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能