When attempting to add an entry to a database via a form submission using Ajax, certain strings containing parenthesis will cause the POST operation to fail, but not in a consistent way.

当尝试使用Ajax通过表单提交向数据库添加条目时,包含括号的某些字符串将导致POST操作失败,但不会以一致的方式。

The relevant POST operation looks like this:

相关的岗位操作如下:

$.ajax(
{
  type: "POST",
  url: "SubmitAnswer.php",
  data: datastring,
  dataType: "json",
  cache: false,
  success: function(data)
  {
    ...
  }
}

The datastring contains a bunch of stuff including a string containing a mathematical expression. If that string contains parenthesis, in certain very specific cases, it will cause the POST operation to fail with a 403 error when the Submit button is clicked.

datastring包含一系列内容,包括一个包含数学表达式的字符串。如果该字符串包含括号,在某些非常特定的情况下,当单击Submit按钮时,将导致POST操作失败,并出现403错误。

Here are some examples of mathematical expression strings that cause a problem:

下面是一些数学表达式字符串导致问题的例子:

(A-B)*C
(A*B)*(C*D)

Here are some examples of mathematical expression strings that do NOT cause a problem:

下面是一些数学表达式字符串的例子,它们不会引起问题:

(A+B)*C
A*(B-C)
(A*B)+(C*D)

It's almost as though certain permutations trip some kind of "protection" flag preventing them from being posted to the database? Or some kind of bizarre parsing error?

几乎就好像某些特定的排列会破坏某种“保护”标志,阻止它们被发布到数据库中?还是某种奇怪的解析错误?

2 个解决方案

#1


1

Doesn't look like you are correctly encoding the keys and / or values in datastring for use in an application/x-www-form-urlencoded request payload.

看起来您并没有正确地编码用于应用程序/x-www-form- urlenencoded的键和/或值。

My advice, let jQuery do the encoding by passing an object, eg

我的建议是,让jQuery通过传递一个对象来进行编码

$.ajax({
  method: 'POST',
  url: 'SubmitAnswer.php',
  dataType: 'json',
  data: {
    edition_id: edition_id,
    nickname: nickname,
    answer: answer,
    email_address: email_address
  }
})

更多相关文章

  1. Jquery Validate 正则表达式实用验证代码常用的
  2. 通过],[和创建json对象来分割字符串
  3. 将Object转换为字符串并返回[复制]
  4. 为什么在使用jquery读写表单输入时必须对字符串进行编码?
  5. 如何设置请求标头字符串[重复]
  6. Jquery验证插件,获取错误字符串
  7. JQuery攻略(三)数组与字符串
  8. 如何确定在web页面上呈现的字符串的长度(以像素为单位)?
  9. 具有不间断空格的呈现字符串

随机推荐

  1. 详解PHP网页缓存技术优点及代码实例
  2. php之 Zend 内存管理器
  3. 速看!主流PHP框架性能非权威测试
  4. php如何进行内存调试
  5. 详解PHP中的OPcache 扩展
  6. PHP使用Closure创建匿名函数的方法介绍
  7. 如何兼容 MySQL + ES + MongoDB 实现上亿
  8. 谈谈PHP中的多进程消费队列
  9. 详解PHP论坛实现积分系统的思路代码
  10. php如何发布扩展信息