Ajax call to php script returns 404 error

Solution:

Since the server sends a 404 (for god knows what reason), there are two ways to fix/circumvent this:

  1. Ignore the HTTP response code and change success to complete in the jQuery ajax call, so that the handler is executed when the request is done no matter the server response. You know the server response (it always works). The HTML should still be available in the jQuery complete handler.
  2. Overwrite the 404 that something sends on the server (probably something WordPress) by executing (before printing any output): header('HTTP/1.1 200 OK'). Since the script is executed, this will overwrite the crazy 404 and jQuery will receive that 200 and execute the success handler.

You could try both =) I’m pretty sure the first one will work (but that’s not so clean). I’m also pretty sure the 2nd will work, but I don’t know WordPress well enough to make promises =)