Is there any data restriction size for the ajax xmlhttprequest mail method, is my xhr disconnected?

I am trying to send some html data to a php script using the post ajax xmlhttprequest method. But for some reason, My XHR POST REQUEST is disabled, and not all data is transferred to my doit.PHP script. However, the same html data from the textarea form is transmitted correctly through the doit.PHP script through the regular mail method of the form! could you guys help me overcome this problem and be able to pass 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); 
+4
source share
2 answers

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

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

This is because POST variables are limited by ampersand ( & ). The problem is probably that your line also contains an ampersand, which will be interpreted as the beginning of a new POST variable.

You can easily check this if you print all the resulting POST variables in a PHP script:

 var_dump($_POST); 
+4
source

This looks like a GET request for me due to a couple of question mark and name / value in the url:

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

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

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

0
source

All Articles