1

Is there any clever way of handling php errors returned in the data object. Currently I occasionally get things like:

<br />
<font size='1'><table class='xdebug-error'
.....

this is generally followed by the json object I'm expecting. Is there any systematic way to look for these errors? An example call I'm using might be:

function getMyCharities(callback) {
$.post("my_file.php", function(data) {
    callback(data);
});
}

In the documentation for jquery I've found:

 .done(function() { alert("second success"); }) 
.fail(function() { alert("error"); })
.always(function() { alert("finished"); });

but these don't handle this type of error as I've tested it. I also don't want to build a error parser if possible.

thanks

2 Answers 2

3

The correct way to handle these errors is to turn off error reporting in PHP. You should not have error reporting turned on for a production site.

With error reporting turned off, all PHP errors will return a HTTP 500 server error which will then be caught by the fail callback of your $.post promise object.

Sign up to request clarification or add additional context in comments.

Comments

0

I think those success/fail methods are with respect to the ajax call made to the server. In your case, the server is returning data with the correct http status. You would need to parse the 'data' object directly on successful callback, to check for signs of failure, (json flag based ({isFailure: 1}) or worst case, string based). If not, you would need the server to somehow fail, so then when the ajax call is made, the call would fail, and you can handle this in the 'fail' callback on the page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.