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.

6 comments:

lookatthosemoose said...

Genius! You just saved me from hours of headaches.

José Coelho said...

Same feeling! You saved me a lot of testing. THANKS.
From the very west,
zecoelho

Anonymous said...

Thanks!!!!!!!!!!!!!!!!!!

Unknown said...

Great...

I wasted my too much time to resolve this problem.

Thankx....

Unknown said...

Great...

I wasted my too much time to resolve this problem.

Thankx....

Unknown said...

Thanks a lot man!!!