View Full Version : Reaction in the case of a wrong JSON format

2 Jun 2009, 6:25 AM
There is a good function for submission of a form over AJAX and reaction on the response. But the case, if the JSON format is wrong, e.g. due to unexpected warnings or notices or programming errors, is not handled efficiently.

E.g. a parse error is reported in the debug console of the browser

missing ) in parenthetical
Parse error: parse error in ...\admin\ajax\authenticate.php on line 28

but neither success nore failure function is called in that case.

This response with damaged json format is however a normal HTTP response, so it is possible, to catch this and report ordinarily in the failure handling function like other ajax communication errors.

2 Jun 2009, 6:31 AM

2 Jun 2009, 6:42 AM
Well, it is not the problem to investigate and bring the json response to the correct format in each concrete case.

E.g. I faced the problem because my json responce was damaged by a php warning. FireBug was off and nothing happened. The processing were continuing perpetually and did not ended with any result.

I mean that it would be good to generally catch such cases and let handle them over the failure call back function.