XMLHttpRequest POST数据大小

3
XHR POST请求有大小限制吗?我正在使用POST方法将文本数据保存到MySQL中,使用PHP脚本,但是数据被截断了。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请求队列,但我不太喜欢这种方式。还有其他方法吗?
1个回答

1

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

<?php phinfo(); ?>

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

嗨,我的“post_max_size”初始值为8M,我将其增加到80M并重新启动了服务器。我认为这不是问题,因为数据首先永远不会达到8M... - user366121
仅仅因为Firebug在处理这个文件大小时有问题并不意味着它不工作;) 你确认过当Firebug控制台没有激活时JS代码是否正常工作了吗? - Tobias P.
我怀疑问题出在哪里。我使用XHR GET方法来检索数据,而GET是有限制的:function retrieveRows() { xmlhttp = createXHR();xmlhttp.open("GET","retrieveRowData.php", false); try { xmlhttp.send(null); } catch(err) { errormessage="此页面发生错误。\n\n"; errormessage+="错误描述:" + err.description + .\n\n"; errormessage+="单击“确定”继续。\n\n"; alert(errormessage); } return xmlhttp.responseText; } - user366121

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接