简体   繁体   English

ajax xmlhttprequest post方法是否有任何数据限制大小我的xhr被截断?

[英]Is there any data limit size for ajax xmlhttprequest post method my xhr get cut off?

I am trying to send some html data to php script using ajax xmlhttprequest post method. 我试图使用ajax xmlhttprequest post方法将一些html数据发送到php脚本。 But for some reason My XHR POST REQUEST is cut off and not all data get transferred to my doit.php script. 但由于某些原因,我的XHR POST REQUEST被切断,并且并非所有数据都被传输到我的doit.php脚本。 However the same html data from textarea form get passed to doit.php script correctly via normal form post method! 然而,来自textarea表单的相同html数据通过普通的表单post方法正确传递给doit.php脚本! could you guys help me overcome this problem and be able to pass this html data via xhr request ? 你能帮助我克服这个问题并能通过xhr请求传递这个HTML数据吗?

    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: 我认为你还应该encodeURIComponent()你的siteContents字符串:

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

That's because POST variables are delimited by an ampersand ( & ). 这是因为POST变量由和号( & )分隔。 The problem probably is that your string is also containing an ampersand which will be interpret as the beginning of a new POST variable. 问题可能是你的字符串也包含一个&符号,它将被解释为新POST变量的开头。

You could easily check this if you output all received POST variables in your PHP script: 如果在PHP脚本中输出所有收到的POST变量,则可以轻松检查:

var_dump($_POST);

This looks like a GET request to me, because of the question mark and name/value pairs in the URL: 这看起来像是对我的GET请求,因为URL中的问号和名称/值对:

http://www.mysite.com/doit.php?Name=test&Id=12345

Here's how to make a POST request with AJAX: 以下是使用AJAX发出POST请求的方法:

http://www.javascriptkit.com/dhtmltutors/ajaxgetpost2.shtml http://www.javascriptkit.com/dhtmltutors/ajaxgetpost2.shtml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM