XMLHttpRequest POST 数据大小
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XHR Post 没有大小限制,但您将数据发送到 PHP 有大小限制;)
创建以下 php 文件并在浏览器中打开它:
现在搜索变量“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:
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)