【问题标题】:Jquery - ERROR 414: Request-URI Too LargeJquery - 错误 414:请求 URI 太大
【发布时间】:2018-12-28 17:09:53
【问题描述】:

我遇到了请求 URI 太大的问题。我在这里查看了各种帖子,建议使用帖子,而不是获取。我已经尝试过了,但我仍然遇到同样的问题。

这是我目前使用的代码:

urlData = encodeURIComponent(JSON.stringify(data))
    $.ajax({
        type: "post", 
        cache: false,
        url: "test.php?urldata=" + urlData,
        success: function(data) {
            console.log(data)
        }
    });

我尝试将$.ajax 更改为$.post,结果相同。

test.php 正在使用$_REQUEST['varname'],我也尝试过$_POST['varname']

如何在不达到此限制的情况下将数据从浏览器发送到后端 php 页面?关于我做错了什么的任何指示。 ?

我无权访问 apache2 进行任何更改。

谢谢

【问题讨论】:

  • 不要在网址上发布数据。使用身体。
  • 谢谢你能给我指出正确的方向吗?
  • 这真的取决于你的data - api.jquery.com/jquery.post

标签: php jquery ajax


【解决方案1】:

您需要做的是在请求的标头中传递大量数据,而不是作为 URL 上的查询字符串。您可以通过使用data 设置对jQuery.ajax() 执行此操作。试试:

$.ajax({
  type: 'POST',
  cache: false,
  url: "test.php", // remove the concat causing the error
  data: data, // send your data via the data setting
  success: function(response) {
    $.publish('/imports/refresh_row', response);
  }
});

然后在 PHP 端,您将能够使用 $_POST['varname'] 检索在 data 对象中发送的单个项目。

【讨论】:

  • 谢谢。我一直在看这个,我没有看到完成后发送的任何数据。在我的 test.php 脚本中,我添加了 print_r(compact(array_keys(get_defined_vars())));,但我发送的数据没有出现。
  • 谢谢我意识到我做错了什么。这很有帮助。
猜你喜欢
  • 2017-12-14
  • 2014-03-28
  • 1970-01-01
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多