三生石@ 2015-07-17 01:23 采纳率: 100%
浏览 27

在ajax表单中使用“&”提交

I am submitting a form using .ajax().

The current script contains:

data: dataString,

dataString contains:

var list    = $('.listsummary').val()

The class listsummary belongs to a textarea which users fill in, or will be (partially) filled in dynamically through a different script.

The problem is that users nearly all of the time use the '&' sign, for example:

Potato & Patota blah blah blah

This screws up the dataString allowing to post everything written before the first '&' is found.

How can I achieve that the var list will be properly sent to the PHP handler in order to store the entire textarea content into the database WITH the use of '&'?

  • 写回答

3条回答 默认 最新

  • weixin_33705053 2015-07-17 01:26
    关注

    You can encode the string with encodeURIComponent()

    var list = $('.listsummary').val();
    var urlEncoded = encodeURIComponent(list);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)