問題描述
對于主要瀏覽器實現,您可以在 XMLHttpRequest
的 send 方法中使用的字符串數據長度是否有文檔記錄?
Is there a documented max to the length of the string data you can use in the send method of an XMLHttpRequest
for the major browser implementations?
當數據超過大約 3k 時,我遇到了 JavaScript XMLHttpRequest
Post 在 FireFox 3 中失敗的問題.我假設 Post 的行為與傳統的 Form Post 相同.
I am running into an issue with a JavaScript XMLHttpRequest
Post failing in FireFox 3 when the data is over approx 3k. I was assuming the Post would behave the same as a conventional Form Post.
W3C 文檔提到 send 方法的數據參數是 DOMString,但我不確定主流瀏覽器是如何實現的.
The W3C docs mention the data param of the send method is a DOMString but I am not sure how the major browsers implement that.
這是我的 JavaScript 的簡化版本,如果 bigText 超過 3k 則失敗,否則它可以工作...
Here is a simplified version of my JavaScript, if bigText is over about 3k it fails, otherwise it works...
var xhReq = createXMLHttpRequest();
function createXMLHttpRequest() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
try { return new XMLHttpRequest(); } catch(e) {}
alert("XMLHttpRequest not supported");
return null;
}
function mySubmit(id, bigText) {
var url = "SubmitPost.cfm";
var params = "id=" + id + "&bigtext=" + encodeURI(bigText);
xhReq.open("POST", url, true);
//Send the header information along with the request
xhReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhReq.setRequestHeader("Content-length", params.length);
xhReq.setRequestHeader("Connection", "close");
xhReq.onreadystatechange = onPostSubmit;
xhReq.send(params);
}
function onPostSubmit() {
if (xhReq.readyState==4 || xhReq.readyState=="complete")
{
if (xhReq.status != 200)
{
alert('BadStatus');
return;
}
}
}
推薦答案
我相信最大長度不僅取決于瀏覽器,還取決于網絡服務器.例如,Apache HTTP 服務器有一個 LimitRequestBody 指令,它允許從 0 字節到 2GB 的數據.
I believe the maximum length depends not only on the browser, but also on the web server. For example, the Apache HTTP server has a LimitRequestBody directive which allows anywhere from 0 bytes to 2GB worth of data.
這篇關于XMLHttpRequest Post 上的 send() 數據參數的最大長度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!