UPDATE: @MESSIAH told me to shorten this. Here is the bare bones version.
I cannot parse my response from an ajax call. I keep going in circles. Google is basically telling me that this is the problem. Well, no matter if I take out json in the ajax call or call parse. It will give me errors.
If parse directly without using JSON.parse(), I get: The first one is: Uncaught TypeError: Cannot read property 'time' of undefined Okay, so that means it is not parsed.
Currently, I am getting this because I am trying to parse: The one I am getting right now is: Uncaught SyntaxError: Unexpected token u Okay, so that means it is parsed.
Here is my ajax call:
var reply; function sendRouteRequest() { $.ajax({ type: 'GET', //contentType: "application/json; charset=utf-8", url: '/api/getReply', data: data, dataType: 'json', success: function(result) { reply = result; console.log(reply); console.log(reply.time); }, error: function(jqXHR, textStatus, errorThrown) { alert("Error: " + textStatus + " exception: " + errorThrown); } });//End of ajax } Here is the relevant code:
function parseJson() { //data = JSON.stringify(reply); jsonData = JSON.parse(reply); console.log(jsonData.time); } Here is what the reply looks like in console.
Object alert: Object points: Array[30] points: Array[30] time: 4.72 __proto__: Object status: Object __proto__: Object But console.log(reply.time) gives me undefined. Wut?
Going in circles.
Geeky
UPDATE: I am calling parseJson() in a function not shown here, $(document).ready(function(){ //blah blah blah}
Servlet returns application/json format