Trying to troubleshoot a seemingly simple issue: The callback function of an AJAX post request is receiving a JSON string in the 'data' parameter.
{"result":"Torte"}
Manually parsing it yields the expected result:
var response = JSON.parse('{"result":"Torte"}');
However, attempting to parse it using the data parameter like this:
var response = JSON.parse("'" + data + "'");
results in an error:
Uncaught SyntaxError: Unexpected token ' in JSON at position 0
at JSON.parse (<anonymous>)
A similar error occurs when trying to parse it without concatenation:
var response = JSON.parse(data);
Chrome's developer tools display:
VM1285:2 Uncaught SyntaxError: Unexpected token < in JSON at position 21
at JSON.parse (<anonymous>)
It seems that 'data' contains extra characters. However, displaying the received JSON string:
$("#idTest").html(data)
shows:
{"result":"Torte"}
with no additional characters present.
I have been trying to solve this issue for hours with no luck. Any assistance would be greatly appreciated.