XMLHttpRequest POST 数据大小

发布于 2024-09-06 07:29:44 字数 919 浏览 1 评论 0原文

XHR POST 请求有大小限制吗?我正在使用 PHP 脚本使用 POST 方法将文本数据保存到 MySQL 中,并且数据被切断。 Firebug 向我发送以下消息:

... Firebug request size limit has been reached by Firebug. ... 

这是我用于发送数据的代码:

function makeXHR(recordData)
{
    xmlhttp = createXHR();

    var body = "q=" + encodeURIComponent(recordData);

    xmlhttp.open("POST", "insertRowData.php", true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", body.length);
    xmlhttp.setRequestHeader("Connection", "close");

    xmlhttp.onreadystatechange = function() 
    {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
        {
            //alert(xmlhttp.responseText);
            alert("Records were saved successfully!");
        }
    }
    xmlhttp.send(body);

}

我能想到的唯一解决方案是拆分数据并创建 XHR 请求队列,但我不喜欢它。还有别的办法吗?

Is there a size limit to a XHR POST request? I am using the POST method for saving textdata into MySQL using PHP script and the data is cut off. Firebug sends me the following message:

... Firebug request size limit has been reached by Firebug. ... 

This is my code for sending the data:

function makeXHR(recordData)
{
    xmlhttp = createXHR();

    var body = "q=" + encodeURIComponent(recordData);

    xmlhttp.open("POST", "insertRowData.php", true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", body.length);
    xmlhttp.setRequestHeader("Connection", "close");

    xmlhttp.onreadystatechange = function() 
    {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
        {
            //alert(xmlhttp.responseText);
            alert("Records were saved successfully!");
        }
    }
    xmlhttp.send(body);

}

The only solution I can think of is splitting the data and making a queue of XHR requests but I don't like it. Is there another way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2024-09-13 07:29:44

XHR Post 没有大小限制,但您将数据发送到 PHP 有大小限制;)
创建以下 php 文件并在浏览器中打开它:

<?php phinfo(); ?>

现在搜索变量“post_max_size”,该变量限制可以发送到 PHP 的最大数据(但可以在 php.ini 中更改)

XHR Post has no size limit, but you're sending data to PHP which has a size limit ;)
Create the following php-file and open it in a browser:

<?php phinfo(); ?>

Now search for the variable "post_max_size", this variable limits the maximum data that can be sent to PHP (but it can be changed in the php.ini)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文