406 Not Acceptable error on live server - JSON

北城余情 提交于 2019-12-24 19:22:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!