Is there a way to get PHP to return an AJAX error code if the PHP script fails somewhere?
I was following a tutorial and typed this in to my PHP:
$return['error'] = true; $return['msg'] = "Could not connect to DB";
And all was well, until I realised it was JSON data. Is there a way to return errors using standard $_POST and returned HTML data (as in, trigger jQuery’s AJAX error: event?
I don’t know about jQuery, but if it distinguishes between successful and unsuccessful (HTTP 200 OK vs. HTTP != 200) Ajax requests, you might want your PHP script respond with an HTTP code not equal to 200: