是否有阿贾克斯xmlhtt prequest POST方法我XHR得到切断任何数据大小限制? [英] Is there any data limit size for ajax xmlhttprequest post method my xhr get cut off?

查看:170
本文介绍了是否有阿贾克斯xmlhtt prequest POST方法我XHR得到切断任何数据大小限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一些HTML数据发送到用ajax xmlhtt prequest post方法PHP脚本。但由于某些原因,我XHR POST请求被切断,而不是所有的数据得到转移到我的doit.php脚本。然而从textarea的形式相同的HTML数据获取传递通过正常的表单提交方法正确doit.php脚本!可能你们帮我解决这个问题,并能够通过XHR请求通过这个网站的内容?

  VAR XMLHTTP;
    如果(window.XMLHtt prequest)
      {// $ C $下IE7 +,火狐,Chrome,歌剧,Safari浏览器
      XMLHTTP =新XMLHtt prequest();
      }
    其他
      {// code对IE6,IE5
      XMLHTTP =新的ActiveXObject(Microsoft.XMLHTTP);
      }
    xmlhttp.onreadystatechange =功能()
      {
      如果(xmlhttp.readyState == 4和&安培; xmlhttp.status == 200)
        {
        的document.getElementById(myDiv)的innerHTML = xmlhttp.responseText。
        }
      }
    xmlhttp.open(POST,http://www.mysite.com/doit.php?Name=test&Id=12345,真正的);
    xmlhttp.setRequestHeader(内容型,应用程序/ x-WWW的形式urlen codeD);
    xmlhttp.send(的outputText =+ siteContents);
 

解决方案

我想你也应该<一个href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/en$c$cURIComponent"相对=nofollow>恩codeURIComponent()您的 siteContents 的字符串:

  xmlhttp.send(的outputText =EN + codeURIComponent(siteContents));
 

这是因为POST变量是由一个连字符分隔(&安培; )。这个问题可能是你的字符串还包含一个与符号,这将是除preT作为一个新的职位变的开始。

你可以很容易,如果检查这一点,你的输出在PHP脚本中所有收到的POST变量:

 的var_dump($ _ POST);
 

I am trying to send some html data to php script using ajax xmlhttprequest post method. But for some reason My XHR POST REQUEST is cut off and not all data get transferred to my doit.php script. However the same html data from textarea form get passed to doit.php script correctly via normal form post method! could you guys help me overcome this problem and be able to pass this html data via xhr request ?

    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("POST","http://www.mysite.com/doit.php?Name=test&Id=12345",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("outputtext="+siteContents);

解决方案

I think you should also encodeURIComponent() your siteContents string:

xmlhttp.send("outputtext=" + encodeURIComponent(siteContents));

That's because POST variables are delimited by an ampersand (&). The problem probably is that your string is also containing an ampersand which will be interpret as the beginning of a new POST variable.

You could easily check this if you output all received POST variables in your PHP script:

var_dump($_POST);

这篇关于是否有阿贾克斯xmlhtt prequest POST方法我XHR得到切断任何数据大小限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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