XMLHttpRequest 请求 URI 太大 (414)

发布于 2024-09-05 21:03:52 字数 868 浏览 1 评论 0原文

好吧,我希望最终一切都会顺利。但当然不是。新问题是以下消息:

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 技术交流群。

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

发布评论

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

评论(1

初心未许 2024-09-12 21:03:52

您应该通过 send 方法在请求正文中 POST rowData。因此,不要发布到 "insertRowData.php" + rowData,而是发布到 "insertRowData.php" 并将 rowData 中的数据传递给 <代码>发送。

我怀疑您的 rowData 是带有问号的查询字符串。如果是这种情况,那么消息正文只是 rowData 而没有前面的问号。

编辑:这样的东西应该有效:

var body = "q=" + encodeURIComponent(recordData);
xmlhttp.open("POST", "insertRowData.php", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = // ...
xmlhttp.send(body);

You should POST rowData in the request body via the send method. So, instead of posting to "insertRowData.php" + rowData, POST to "insertRowData.php" and pass the data in rowData to send.

I suspect that your rowData is a query string with the question mark. If that is the case, then the message body is simply rowData without the prepended question mark.

EDIT: Something like this should work:

var body = "q=" + encodeURIComponent(recordData);
xmlhttp.open("POST", "insertRowData.php", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = // ...
xmlhttp.send(body);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文