406响应与$.post请求jQuery到外部PHP


406 response with a $.post request jQuery to external PHP

我试图通过jQuery中的$.post发布大量文本并获得406响应。它可以在300个字符左右工作。下面是我的代码:

index . php

<form class="formss" action="index.php">
    <textarea id="submittts" name="tts" spellcheck="false"></textarea>
</form>
jQuery

$('.save').click(function() {
    $.post('store.php', $('.formss').serialize())
});

store.php

<?php
$tts = $_POST['tts'];
$texttostore = $tts;
$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "notes";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "INSERT INTO notes (code)
VALUES ('$texttostore')";
if ($conn->query($sql) === TRUE) {
    echo stripslashes(str_replace(''r'n',PHP_EOL,$texttostore));
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>

. htaccess

<IfModule mod_security.c>
SecFilterCheckURLEncoding Off
</IfModule>

得到以下响应:https://i.stack.imgur.com/MUZpX.png

我也尝试过本地表单提交,但它也会带来一个错误的请求。

注意:存储时保留所有空白和格式,这是有意的

如果有人能帮我,那就太好了,谢谢:)

Web浏览器请求来自服务器的信息。当这种情况发生时,它发送一个Accept报头。这告诉服务器浏览器可以接受什么格式的数据。如果服务器不能发送Accept报头请求的格式的数据,服务器发送406 Not Acceptable error

从评论中附上的截图可以清楚地看到,响应头中的charsetiso-8859-1。只需以UTF-8编码发送响应,就可以解决问题。