问题
I've just moved a site to live and am getting a 406 Not Acceptable error when using jquery to make an ajax request to a php script. I don't get the error on my test server so I'm just trying to figure out the correct way to fix this. The AJAX request is as follows, and expects JSON response, while my php script is just echoing out with json_encode().
$.ajax({
type: "POST",
contentType: "application/json",
data: "{}",
url: "server/php/progress.php",
dataType: "json",
EDIT: here's the crux of my php script (have also tried without the header setting):
header('Content-type: application/json');
echo json_encode($val);
exit;
Any thoughts on what should be done to fix this? htaccess directives?
回答1:
Not acceptable will be triggered based on Accept, Accept-Charset, Accept-Language headers. So if your code is identical, it's likely that there's some setting related to content negotiation turned on there.
回答2:
Aargh. Just switching it to GET sorted the issue. I'm not sure why on earth I was using POST for retrieval.
Still not sure why the issue didn't happen on my local wamp server, some difference in the apache settings somewhere.
来源:https://stackoverflow.com/questions/11645844/406-not-acceptable-error-on-live-server-json