Friday, February 26, 2016

PHP server serving valid content but still returning status code 404

Scenario:

You have an ajax script get-data.php which should return valid JSON data.

When you use your web browser to open the page, everything looks good, and you can seee the JSON.

However, when you issue a jQuery AJAX call, it always returns error 404.

In my case, I wasn't checking carefully enough, because the page returned the status code 404, even it served the content properly. This was probably caused by WP functions included in my script.

When I used http_status_code(200) manually, all went back to work :)

Moral  of the story: Your  scripts sometimes contain extra code which can cause troubles. :O

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...