Google Analytics

Thursday, February 05, 2009

406 Not Acceptable error using jQuery AJAX

I was scratching my head over a problem today where a jQuery ajax request was failing on one particular web server with a '406 Not Acceptable' error. It had been tested on many other servers without any trouble, but this seemingly normal Apache server wasn't having a bar of it.

It turned out the problem was that I was submitting the ajax request using the POST method but not actually sending any post data. For example:

$.ajax({
   type: "POST",
   url: "index.php?action=foo",
   success: function(msg){
     // ...
   }
 });

Changing it to a GET sorted out the problem.