I have the following code and output, and I cant fine any error on the json data to be decoded. Can anyone please help me in finding this error
CODE:
When you specify dataType : json, result is already parsed in jQuery.
Moreover, complete function argument is returning an object representing the result not the result itself.
That case you should use var top10Value = JSON.parse(data.responseText)
;
data returned already json format only,
$.ajax({
'type': 'get',
'data': {},
'dataType': 'json',//Return Json Format
'url': 'dashboard/data/',
'complete': function(data) {
//data returned already json format only
//var top10Value = JSON.parse(data);
$.each(top10Value, function(key,value){
console.log(key+" -- "+value);
});
}
});
jQuery is clever enough to parse the response as it is, even if dataType
isn't specified.
In your case, it is specified and therefore, it is already parsed and data
is the parsed JSON object.
What you are doing is therefore parsing an Object
.
Doc says:
dataType: (default: Intelligent Guess (xml, json, script, or html))
Type: String
The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are: