Hi everyone,
I encounter a problem with promise in my ionic application that I develop to succeed my school degree.
I have a PHP API server who send me back a JSON in text format when I post a request like registering a new user.
This request is made by a provider and the reponse from the server is parsed into JSON format by JSON.parse function on the resolve function that I return. Just like this:
TEST_API(){
return new Promise((resolve, reject) => {
let user = {pseudo:'francouille',password:'Tozoo$123',confirmPassword:'Tozoo$123',email:'zango@tozoo.fr'};
let data: URLSearchParams = this.serialize(user);
let url = "http://api-liwee.local/register/";
let http = new XMLHttpRequest();
http.open("POST", url, true);
http.onload = () => resolve(JSON.parse(http.responseText));
http.onerror = () => reject(http.statusText);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send(data);
});
}
After that I console.log() the returned promise from another page of my application who call this funtion, just like this:
reponse : Promise<any>;
TestAPI() {
this.reponse=this.apiProvider.TEST_API();
console.log(this.reponse);
}
And my problem is now, I get this on my firefox console:
{…}
__zone_symbol__state: true
__zone_symbol__value: {…}
error: Object { code: "PSEUDO_ALREADY_USE", message: "Le pseudo que vous avez indiqué est déja utilisé par un autre utilisateur." }
success: false
__proto__: Object { … }
__proto__: Object { then: then(), catch: catch(), … }
So the values that interest me are on the __zone_symbol__value
field of this object, but I can’t acces them with: this.response.__zone_symbol__value
like the others objects I used before.
I hope somebody can help me for this problem.
Thanks.
François.