javascript - Is there any data limit size for ajax xmlhttprequest post method my xhr get cut off? - Stack Overflow

I am trying to send some html data to php script using ajax xmlhttprequest post method. But for some re

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 overe 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",".php?Name=test&Id=12345",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("outputtext="+siteContents);

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 overe 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./doit.php?Name=test&Id=12345",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("outputtext="+siteContents);
Share Improve this question edited Feb 3, 2013 at 21:08 user1788736 asked Feb 3, 2013 at 21:01 user1788736user1788736 2,84521 gold badges68 silver badges118 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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

This looks like a GET request to me, because of the question mark and name/value pairs in the URL:

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

Here's how to make a POST request with AJAX:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744599805a4583113.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信