[英]406 response with a $.post request jQuery to external PHP
I'm trying to post large amounts of text via $.post
in jQuery and getting a 406 response. 我试图通过$.post
在jQuery中发布大量文本,并得到406响应。 It works fine under around 300 characters. 它可以在300个字符以下正常工作。 Below is my code: 下面是我的代码:
index.php index.php
html html
<form class="formss" action="index.php">
<textarea id="submittts" name="tts" spellcheck="false"></textarea>
</form>
jQuery jQuery的
$('.save').click(function() {
$.post('store.php', $('.formss').serialize())
});
store.php 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 .htaccess
<IfModule mod_security.c>
SecFilterCheckURLEncoding Off
</IfModule>
Getting the following response: http://i.stack.imgur.com/MUZpX.png 得到以下响应: http : //i.stack.imgur.com/MUZpX.png
Have also tried with a local form submit, but it would also bring up a bad request. 也尝试过使用本地表单提交,但这也会提出一个错误的请求。
Note: All whitespace and formatting is preserved when stored, and that is intentional 注意:所有空白和格式在存储时都会保留,这是有意的
If anyone could help me out that would be great, thanks :) 如果有人可以帮助我,那就太好了,谢谢:)
Web browsers make a request for information from the server. Web浏览器从服务器请求信息。 When this happens, it sends an Accept
header. 发生这种情况时,它将发送一个Accept
标头。 This tells the server in what formats the browser can accept the data. 这告诉服务器浏览器可以接受哪种格式的数据。 If the server cannot send data in a format requested in the Accept
header, the server sends the 406 Not Acceptable error
. 如果服务器无法以Accept
标头中请求的格式发送数据,则服务器将发送406 Not Acceptable error
。
From the screenshot attached in the comments, you can see clearly that charset
in response headers is iso-8859-1
. 从注释中的屏幕截图中,您可以清楚地看到响应头中的charset
集是iso-8859-1
。 Just send the response in UTF-8
encoding and that should solve the issue. 只需以UTF-8
编码发送响应即可解决此问题。
Have a look at this SO link for setting charset header in PHP response. 看看这个用于在PHP响应中设置字符集标头的SO链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.