How do I send a large amount of data to a server?

I am using Ajax to send a large text box to a server script, however, when the textbox has a lot of data it fails. Is there a better way for me to do this?

Here is my code.

<script type="text/javascript">
function testmail()

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)

var subject = "subject=" + document.getElementById('subject').value;
var testemail = "&email=" + document.getElementById('testaddress').value;
var mbody = "&body=" + document.getElementById('ha').value;"POST","newmailer.php?" + subject + testemail + mbody ,true);


Thanks in advance.

it was easy for me to pick up because I used to make the same mistake :headbang: :frowning:

Hah, good catch Kalon. Serves me right for not paying proper attention!

I am a little curious about this line in your code"POST","newmailer.php?" + subject + testemail + mbody ,true);

That would be ok if the method was GET and not POST.

I thought if using POST you have to send the paramaters separately.

I use this to send POST ajax requests

    var url   = "captchaCompare.php";
    var params  = "";
    params = "txtUserAns="+userAns+"&sid="+Math.random();"POST",url,true);
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

I think with GET there is a max number of chars you can send in the query string (not sure what it is off the top of my head).

Could it be that because you are appending your query string to the url, the request is being sent as a GET even though you have set it as a POST?

Try sending your query string parameters separately as above and see if that helps.

Try setting the request header’s content-type to this:

xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

Hi, yes, I do not get any response when I send a large amount of text. Maybe there is a limit on the amount of data I can send?

Have you checked what the reason for the failure is? This might be easier to fix than to just figure out a different route. You can start by seeing what the response from the server is - it might be some error message.

Thanks Kalon, great help :slight_smile: