Ajax POST请求被裁剪 [英] Ajax POST-Request gets cropped

查看:101
本文介绍了Ajax POST请求被裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码执行POST请求:

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

generate.php的位置如下:

<?php

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

现在的问题是,如果我发送长文本,它们总是会被裁剪.我试图在php.ini中增加post_max_size,但是没有成功.顺便说一句,我正在使用XAMPP.

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.

我将不胜感激.

推荐答案

(在您描述的情况下)通常有3种方式可以限制内容(假设您的AJAX请求正确):

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

  1. 也许您的字符格式不同,所以您需要确保它们符合库或脚本的要求(如果需要,请转义),以使其在浏览器中显示.

  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.

在这种情况下(如@Mark所说):您将需要使用encodeURIComponent(yourVar)对&进行编码以正确输出它.这将导致它转换&以将其编码为%26并导致正确的输出.

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.

PHP限制了您的内容-您需要更改 post_max_size .但是您已经尝试过了,因此应该尝试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.

Apache服务器正在限制您的内容-您可以使用

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.

这篇关于Ajax POST请求被裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆