Ajax POST-Request被裁剪

I'm using the following code to perform a POST-request:

function sendAjaxRequest(text) {
  var xmlhttp;

  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
  } else {
    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  }

  xmlhttp.onreadystatechange=function() { 
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById('results').innerHTML = xmlhttp.responseText;
    }
  }

  xmlhttp.open('POST', 'generate.php', true);
  xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  xmlhttp.send('code=' + text);
}

Where generate.php looks like this:

<?php

echo isset($_POST['code']) ? $_POST['code'] : '';

The problem now is that if I send long texts they alway get cropped. I tried to increase post_max_size in php.ini but wasn't successful. Btw I'm using XAMPP.

I'd appreciate any guidance.

There are generally 3 ways (in the situation you described) in which content can be limited (assuming your AJAX request is correct) :

  1. Maybe your characters are of a different format so you will need to make sure they conform (escape them if needed) to the requirements of the libraries or scripts for them to be displayed in the browser.

    In this case (as @Mark said): You will need to encode the & using encodeURIComponent(yourVar) to output it properly. This will cause it to transform the & to be encoded as %26 and lead to proper output.

  2. PHP is limiting your content - You need to change the post_max_size in php.ini file. But you have already tried it so you should try 2.

  3. Apache server is limiting your content - This you can manipulate with the LimitRequestBody directive. This can be set to a limit from 0 bytes to 2 GB.