406 Not Acceptable error on live server - JSON

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

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?

Did you try calling the script directly from your browser (that is typing the url to it) ? Does it give the same error ?

If I access the php script from the browser, it correctly outputs the data I expect. Bit baffled by this one!

So we know it’s not the script that’s causing the error. It must be the call. No idea why though.
Try googling for ‘jquery ajax 406’, there are lots of results. This one might be interesting:

Aargh. Just switching it to GET sorted the issue. I’m not sure why on earth I was using POST for retrieval. Thanks, that link pointed me in the right direction :slight_smile:

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