Ajax POST请求被裁剪

编程入门 行业动态 更新时间:2024-10-27 06:28:09
本文介绍了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) :

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

  • 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服务器正在限制您的内容-您可以使用 LimitRequestBody指令.可以将其设置为从0字节到2 GB的限制.

    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请求被裁剪

    本文发布于:2023-10-12 01:10:06,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1483335.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Ajax   POST

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!