XMLHttpRequest 请求 URI 太大 (414)
好吧,我希望最终一切都会顺利。但当然不是。新问题是以下消息:
Request-URI Too Large
请求的 URL 长度超过 该服务器的容量限制。
我担心的是我必须找到另一种传输数据的方法或者是否有可能的解决方案?
XHR函数代码:
function makeXHR(recordData)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var rowData = "?q=" + recordData;
xmlhttp.open("POST", "insertRowData.php"+rowData, true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-Length",rowData.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
alert("Records were saved successfully!");
}
}
xmlhttp.send(null);
}
Well I hoped everything would work fine finally. But of course it doesn't. The new problem is the following message:
Request-URI Too Large
The requested URL's length exceeds the
capacity limit for this server.
My fear is that I have to find another method of transmitting the data or is a solution possible?
Code of XHR function:
function makeXHR(recordData)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var rowData = "?q=" + recordData;
xmlhttp.open("POST", "insertRowData.php"+rowData, true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-Length",rowData.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
alert("Records were saved successfully!");
}
}
xmlhttp.send(null);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该通过
send
方法在请求正文中 POSTrowData
。因此,不要发布到"insertRowData.php" + rowData
,而是发布到"insertRowData.php"
并将rowData
中的数据传递给 <代码>发送。我怀疑您的
rowData
是带有问号的查询字符串。如果是这种情况,那么消息正文只是rowData
而没有前面的问号。编辑:这样的东西应该有效:
You should POST
rowData
in the request body via thesend
method. So, instead of posting to"insertRowData.php" + rowData
, POST to"insertRowData.php"
and pass the data inrowData
tosend
.I suspect that your
rowData
is a query string with the question mark. If that is the case, then the message body is simplyrowData
without the prepended question mark.EDIT: Something like this should work: