I have over 50 scripts where I use an Ajax call to populate a DataTable. All work great. Now I have the need to use an Ajax call that will access a mySQL database and return information to simply display on a page via Javascript.
// Inform user of the error and log to console for debugging
var errMessage = "The following error occured: " + textStatus + ' - # ' + errorThrown;
alert(errMessage);
console.error(errMessage);
});
// callback handler that will be called regardless if failed or succeeded
request.always(function () {
// reenable the inputs
});
});
});
The above produces the following error at line 24
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
Removing the comment tag at line 6 and changing line 24 to
var aData = jQuery.parseJSON(jsonData);
results in a valid result.
I assume that the problem is with the Ajax code or with the use of the returned array. Given that I am a novice in this area I have no clue as to what to do. All of the on-line examples I can find make use of the in-line array which really doesn't address the issue of using an Ajax call.