jQuery: Ajax post calls error handler even when proper response given

When using an AJAX post with the dataType JSON, be careful when returning a valid HTTP response (200) with an empty string as the content.

If the JSON fails to validate, it will call the error handler.

This was encountered when using jQuery v1.2.6, so I updated to v1.4.2 and it worked again.

Otherwise, you can add a check in the error handler to validate the error's status (so if its 200 then ignore) or check the response HTML if its an empty string.

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog