I’m getting crazy from this morning.
I’m tring to get json from web server and display it in a master-detail pattern.
I don’t know what I’m wrong.
This is the file bb.json
{
"id": 0,
"name": "Ben Sparrow",
"lastText": "You on your way?",
"face": "img/ben.png"
}
I used the base template (tabs) by replacing the var chats[] that contains some fake data with this:
// Might use a resource here that returns a JSON array
var chats = $http.get('http://mywebsite/bb.json').then(function(response){
data = response.data;
console.log("aaaaaaaaaaaaaaaaaaaa" + data); //the data is correctly logged
console.log("chats inizializz");
return data;
});
All the remaining functions of the service and the controller are not modified.
Nothing work. Please help me, what I can do? I’m unable to get it works.
Any helps or suggestion is appreciated.
I allow Acces-Control-Origin and from the Chrome Dev Tools I can see that the file bb.json is downloaded
Does the console log return aaa + data? If not then it either be your json file is missing the array brackets
or just return data = response not data = response.data
var chats = $http.get(‘http://mywebsite/bb.json’).then(function(response){
data = response;
console.log(“aaaaaaaaaaaaaaaaaaaa” + data); //the data is correctly logged
console.log(“chats inizializz”);
return data;
You can see you received some data, as you log you [Object object].
If you do your debug with a web browser, just do console.log(response.data) to see your clear JSON object in your web console.
If you only use Xcode or Eclipse to see the log flow, use console.log(JSON.stringify(response.data)), and you will be able to see your JSON.