406直播服务器上无法接受的错误 - JSON器上、错误、JSON

2023-09-02 01:08:32 作者:故作高冷

我刚刚搬到一个网站的生活和我使用jquery时做出一个Ajax请求PHP脚本得到一个406不可接受的错误。我没有得到错误我的测试服务器上,以便我只是试图找出解决这一问题的正确方法。 AJAX请求如下,并期望JSON响应,而我的PHP脚本只是呼应了与 json_en code()

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",

编辑:这里是我的PHP脚本的关键(也尝试无头设置):

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;

这应该做些什么来解决这个问题有什么想法? htaccess的指令?

Any thoughts on what should be done to fix this? htaccess directives?

推荐答案

AARGH。只要切换到GET排序的问题。我不知道为什么在地球上我是用POST进行检索。

Aargh. Just switching it to GET sorted the issue. I'm not sure why on earth I was using POST for retrieval.

不过不知道为什么,这个问题并没有发生我的本地瓦帕服务器上,在apache设置某个地方一定差异。

Still not sure why the issue didn't happen on my local wamp server, some difference in the apache settings somewhere.