php - What can trigger an Ajax 404 error on url that exists... and works?
I make an ajax call on an url that does exists, and does work, even when called with ajax.
Checking with firebug, the POST request fail due to a 404 error, but if I expand the data about the post request, in the response tab, I do find correctly the data that it is supposed to return.
So, everything is working (this is an login system, and users gets logged in), but the page still results as 404 error.
I don't have any clue about what can be causing this. I'm not sure either what code should I post, since this looks to me very strange and unexplainable. By the way, the same code seems to work on other pages. Anyone has some idea of what could possibly causing this kind of behaviour?
I still don't understand the problem, but I got it fixed. As Derik Nel suggested, the script might return some headers I wasn't aware of. That does seem to be the problem, although I can't figure out where and out, especially considering that headers_sent(); doesn't return anything
Yet, after I ADDED a header('HTTP/1.1 200 OK'), which overwrites whatever header was being returned (seemengly by wordpress), and now it works! I got the idea from here Ajax call to php script returns 404 error
This can happen if you're doing a server-side redirect within the URL that you're calling via Ajax, and the URL that you're being redirected to is incorrectly formed, or doesn't exist.
If this is what's happening, the error you're seeing is likely the http error that's being thrown by the redirect. A better way to see what's going on is to check with a tool such as Fiddler and examine the actual http request. In the described scenario, you'll see 2 requests being made, one of which is the faulty redirect.