I have this ajax request:
var rootURL = "http://localhost/myapp/api/api.php"; $.ajax({ type: 'GET', url: rootURL + '/favourites', dataType: "json", success: function(list) { }, error: function(list) { } }); and the api.php makes a query to DB and the encoded result
echo '{"result": ' . json_encode($result) . '}'; is like this:
{ "result": [ { "ID": "1", "username": "username1", "name": "name1", "year": "year1" }, { "ID": "2", "username": "username2", "name": "name2", "year": "year2" } ] } Now how can I get and print the two rows of the JSON result list in success callback in Javascript? I tried this:
var decoded = JSON.parse( lista ); but I receive an error: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Thanks
echo json_encode($result);