发送()数据参数对XMLHtt prequest后最大长度 [英] Max length of send() data param on XMLHttpRequest Post

查看:332
本文介绍了发送()数据参数对XMLHtt prequest后最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有记载的最大的字符串数据,你可以在一个XMLHtt prequest发送方法使用的主要浏览器实现的长度?

我遇到了一个问题,一个JavaScript XMLHtt prequest后未能在Firefox 3中,当数据超过约3K。我是假设后会具有相同的行为作为一个传统的表单提交。

在W3C文档提到的发送方法的数据参数是上DOMString,但我不知道各大浏览器是如何实现的。

下面是我的JavaScript,如果bigText超过约3K失败,否则它的工作原理...

的简化版本

  VAR xhReq = createXMLHtt prequest();

功能createXMLHtt prequest(){
  尝试{返回新的ActiveXObject(MSXML2.XMLHTTP); }赶上(五){}
  尝试{返回新的ActiveXObject(Microsoft.XMLHTTP); }赶上(五){}
  尝试{返回新XMLHtt prequest(); }赶上(五){}
  警报(不支持XMLHtt prequest);
  返回null;
}

功能mySubmit(ID,bigText){
  VAR URL =SubmitPost.cfm;
  VAR PARAMS =ID =+编号+&放大器; bigtext =EN + codeURI(bigText);

  xhReq.open(POST,网址,真实);

  //发送的标题信息与请求一起
  xhReq.setRequestHeader(内容型,应用程序/ x-WWW的形式urlen codeD);
  xhReq.setRequestHeader(内容长度,params.length);
  xhReq.setRequestHeader(连接,关闭);

  xhReq.onreadystatechange = onPostSubmit;
  xhReq.send(PARAMS);
}

功能onPostSubmit(){

  如果(xhReq.readyState == 4 || xhReq.readyState ==完成)
     {
     如果(xhReq.status!= 200)
        {
        警报('BadStatus');
        返回;
        }
    }
}
 

解决方案

我相信最大长度不仅取决于浏览器,而且还上的Web服务器。例如,在Apache HTTP服务器有一个 LimitRequestBody指令允许从0字节到任何地方2GB价值的数据。

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?

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.

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.

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;
        }
    } 
}

解决方案

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.

这篇关于发送()数据参数对XMLHtt prequest后最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆