This is the problem I experienced from 3 days ago.
I am trying to display json data from web api which i am hosting in matesoftyo.cf.
is your php api returning correct response. check in browser or using any other api client like postman
this in postman
this in browser
I thought something was wrong in my API web script, because I can display json data from https://randomuser.me
can you give me script web api
try this block of code…and see what’s printing on the console.
return new Promise(resolve => {
this.http.get('matesoftyo.cf')
.map(res => res.json())
.subscribe(data => {
this.data = data;
console.log(this.data);
resolve(this.data);
});
});
also make sure to have Cordova Whitelist
plugin.
and add <allow-navigation href="http://*/*" />
in your config.xml file.
on the console.
did you install the cordova whitelist
plugin?
done
u can get my script in here
https://drive.google.com/open?id=0Bzs_MHhwhB7pSlpGX0JTOXp1Z1E
Help me to solve this problem
try this and see if the response from this api is coming or not from your code…
return new Promise(resolve => {
this.http.get('https://randomuser.me/api')
.map(res => res.json())
.subscribe(data => {
this.data = data;
console.log(this.data);
resolve(this.data);
});
});
everything is same I have just used an diiferent api url to see if there is any problem with your api or with your code…if the response comes in this case then there is your problem with your api else…
First: Please edit your post and use the </>
button above the post input field to format your code or error message or wrap it in ```
(“code fences”) manually. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.
Then from everything you posted your server is returning an error 500 - both to your app and to Postman (see in he right middle of Postman). Check the network tab of your developer tools, too.
That your webserver outputs valid data anyway is funny and strange. You should check your webserver error logs to see what is going wrong. You might want to just put a simple static .json file on the server to validate that your Ionic code is working correctly if you don’t believe me.
I really wish this idiom would die on its own, but it seems to be extremely resilient. There is no need to instantiate a Promise
here. If all you’re trying to do is spit the response to console,
this.http.get(url).subscribe(rsp => console.log(JSON.stringify(rsp));