Maybe you have an issue with a server, which is sometimes returning either a JSON string with some useful data, and at other times server returns an error message string, which is produced by the PHP function mysql_error(). A simple solution to this problem would be to test whether this data is a JSON string or an error message.
A straightforward answer to a question on how to test if a string is JSON or not would be to use JSON.parse function isJson(str), like so:
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}