I have this code:
$.ajax({
dataType: \'text\',
url: \'/_/js/answers.json\',
type: \"GET\",
success: funct
The '
characters around your JSON make it a JavaScript string and don't form part of the data.
It looks like you have those characters in the JSON that you are requesting over HTTP so there they do form part of the data.
This is not valid JSON. Remove the quotes.
You should have:
{"code": 123}
Not
'{"code": 123}'
Try changing dataType to JSON:
$.ajax({
dataType: 'JSON',
url: '/_/js/answers.json',
type: "GET",
success: function (data) {
alert(data);
alert(data.code);
var result = JSON.parse(data);
var hey = JSON.parse('{"code": 123}');
alert(hey.code);
alert(result.code);
},
error: function () {
alert("code not found");
}
});