【问题标题】:Sending post-data with jquery produces 406 error使用 jquery 发送后数据会产生 406 错误
【发布时间】:2014-09-09 22:24:35
【问题描述】:

我有一个带有 tinymce-textfield 的表单,我使用 jQuery 的 $.post 命令将其内容发送到 php 脚本。

这在大多数情况下都可以正常工作,除非我在该文本字段中有一个如下所示的表单(它是一个 PayPal-Donate 表单):

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input name="cmd" type="hidden" value="_s-xclick" /> <input name="hosted_button_id" type="hidden" value="xxxxxx" /> <input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" type="image" /> <img src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" alt="" width="1" height="1" border="0" /></form>
<p><strong>Make a monthly donation</strong></p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input name="cmd" type="hidden" value="_s-xclick" /> <input name="hosted_button_id" type="hidden" value="xxxx" />
<table>
<tbody>
<tr>
<td><input name="on0" type="hidden" value="Make a monthly donation" /></td>
</tr>
<tr>
<td><select name="os0">
<option value="$10 Month">$10 Month : $10.00 USD - monthly</option>
<option value="$25 Month">$25 Month : $25.00 USD - monthly</option>
<option value="$35 Month">$35 Month : $35.00 USD - monthly</option>
<option value="$50 Month">$50 Month : $50.00 USD - monthly</option>
<option value="$100 Month">$100 Month : $100.00 USD - monthly</option>
<option value="$125 Month">$125 Month : $125.00 USD - monthly</option>
<option value="$140 Month">$140 Month : $140.00 USD - monthly</option>
<option value="$200 Month">$200 Month : $200.00 USD - monthly</option>
<option value="$250 Month">$250 Month : $250.00 USD - monthly</option>
<option value="$300 Month">$300 Month : $300.00 USD - monthly</option>
</select></td>
</tr>

<tr>
<td><input maxlength="200" name="os1" type="text" /></td>
</tr>
</tbody>
</table>
<input name="currency_code" type="hidden" value="USD" /> <input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" type="image" /> <img src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" alt="" width="1" height="1" border="0" /></form>

奇怪的是,它可以在我的本地网络服务器上运行。但是当我把它放在实时服务器上时,它会产生所说的 406 错误......

有什么想法吗?

[编辑]

这里是javascript:

var serial = $('#frmPageEdit').serialize();

serial = serial + "&fid_navigation=" + id + "&action=save_page";

$.post('pages.html', serial, function(data){

            var result = _pagesSplitResponse(data);
            // Do some stuff with the response here...

            window.alert(_pagesTranslations['seite_gespeichert']);
}

再次 - 它适用于所有其他内容,只是上面的表单导致错误...

【问题讨论】:

  • 请出示您的 Javascript。
  • 在编辑中发布了js
  • 尝试将其切换为GET 请求。 PHP 脚本可能不支持POST。参考:stackoverflow.com/questions/11645844/…
  • 嗯,它确实支持 POST。我编写了 PHP 脚本,它成功地处理了其他内容。我确实追踪到了这个表格。当我从内容中删除表单时,脚本会愉快地接受 POST 数据并执行它应该做的事情。

标签: javascript php jquery


【解决方案1】:

事实证明,是服务器上的一些 XSS 机制导致了错误。不确切知道表单的哪个部分导致了错误,但我怀疑是输入字段。

对于遇到相同问题的任何人,以下是解决方案:

在提交之前对导致问题的表单变量使用某种 base_64 编码(例如:https://github.com/carlo/jquery-base64 用于 jQuery),然后在接收 PHP 脚本中的 base_64 解码。

造成一些麻烦的一件事是我使用 tinyMCE 作为编辑器,它添加了一个

围绕 base_64 编码的字符串。因此,解码首先失败。因此,请确保在解码之前从编码字符串中剥离每个 HTML 元素。

希望对大家有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 2016-07-15
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 2018-06-12
    相关资源
    最近更新 更多