Jquery - 错误 414:请求 URI 太大



我遇到了请求 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 来在那里进行任何更改。

谢谢

您需要做的是在请求的标头中传递大量数据,而不是作为 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 对象中发送的各个项目。