Hello,
The more I’m working on the consumption of my web service, the more I’m getting lost…
I run my Ionic project onto the google chrome browser, I had to install the cors plugin on my browser to run my web service,it works when I use the ionic cordova run browser line command (also, I found a bug by using this command line, I published an issue, I hope it will be solved very soon).
So, I’m having a huge problem I can’t understand, it’s with this code :
let ws_function="DonnerConnexion";
let ws_param="aLogin="+encodeURIComponent(param_email)+"&aMDP="+encodeURIComponent(param_pwd)
let url_connection=this.url_ws+ws_function+"?"+ws_param;
let ws_retour={
ok: 0,
Identifiant: "",
Nom: "",
Prenom: "",
AncienneteGroupe: "",
Adresse: "",
Ville: "",
CodePostal: "",
liberreur: ""
};
// don't have the data yet
let myHeaders = new Headers();
myHeaders.append('Accept', 'application/json');
myHeaders.append('Content-Type', 'application/json');
this.response=null;
this.data=null;
let options = new RequestOptions({headers: myHeaders});
this.http.get(url_connection,options)
.subscribe(
data => {this.data=JSON.stringify(data);
let obj=JSON.parse(this.data);
let obj2=obj[Object.keys(obj)[0]];
let obj3=null;
eval("obj3 = ("+obj2+")");
ws_retour.Identifiant=obj3.result.Identifiant.trim();
ws_retour.Nom=obj3.result.Nom.trim();
ws_retour.Prenom=obj3.result.Prenom.trim();
ws_retour.AncienneteGroupe=obj3.result.AncienneteGroupe.trim();
ws_retour.Adresse=obj3.result.Adresse.trim();
ws_retour.Ville=obj3.result.Ville.trim();
ws_retour.CodePostal=obj3.result.CodePostal.trim();
ws_retour.liberreur=obj3.result.liberreur.trim();
if(ws_retour.liberreur==""){ws_retour.ok=1;}
else {ws_retour.ok=0;}
alert(ws_retour.Identifiant); //here, I get a value
},
err=>alert(err)
);
alert(ws_retour.Identifiant); //here, the value is empty, why??
If I put a alert(ws_retour.Identifiant) when the call of my web service is a success, I can retrieve the different values (the returned value is a JSON object), but after it’s call, the different values I saved are erased, how I can solve this new problem? the ws_retour variable is used as a returned value to my local function.
Thanks