Error reading Json on Ionic

0

Good night, I have an ionic project that would communicate with a php, but I can not read the data returned by php on ionic.

function on home.ts page

realizarLogin() {
    this.authServiceProvider.logar(this.model.email, this.model.password)
      .then((result: any) => {

        console.log(result);

        if(result.data == "00-4A"){ 
          this.toast.create({ message: 'Usuário desativado', position: 'botton', duration: 3000 }).present();
        }
        else if(result.data == "00-3A")
        {
          this.toast.create({ message: 'Usuário e/ou senha inválidos.', position: 'botton', duration: 3000 }).present();
        }
        else 
        {
          this.toast.create({ message: 'registro '+ result.data, position: 'botton', duration: 3000 }).present();
          this.navCtrl.push('MenuInternoPage', { result: user.data });
        }
      }) 
      .catch((error: any) => {
        this.toast.create({ message: 'Erro ao efetuar login. Erro: ' + result.data, position: 'botton', duration: 3000 }).present();
      });

function on auth-service.ts page

logar(email: string, password: string) {
return new Promise((resolve, reject) => {
  this.http.post(this.API_LOGIN + '&email='+email+'&password='+password)
    .map(res => res.json())
    .subscribe(data => {
        console.log(data);
    },
    (err) => {
      reject(err);
    });
});

}

Return from php

{'success':true, 'data':"00-3A"}

Error that occurs when sending the data to the ionic, I have the webservice return and then the error below

 ERROR Error: "Uncaught (in promise): ReferenceError: result is not defined
[47]/HomePage.prototype.realizarLogin/<@http://localhost:8100/build/main.js:395:34
F</l</t.prototype.invoke@http://localhost:8100/build/polyfills.js:3:14974
onInvoke@http://localhost:8100/build/vendor.js:5134:24
F</l</t.prototype.invoke@http://localhost:8100/build/polyfills.js:3:14901
F</c</r.prototype.run@http://localhost:8100/build/polyfills.js:3:10124
f/<@http://localhost:8100/build/polyfills.js:3:20240
F</l</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:15649
onInvokeTask@http://localhost:8100/build/vendor.js:5125:24
F</l</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:15562
F</c</r.prototype.runTask@http://localhost:8100/build/polyfills.js:3:10815
o@http://localhost:8100/build/polyfills.js:3:7887
F</h</e.invokeTask@http://localhost:8100/build/polyfills.js:3:16823
p@http://localhost:8100/build/polyfills.js:2:27646
v@http://localhost:8100/build/polyfills.js:2:27893
    
asked by anonymous 07.12.2018 / 00:05

1 answer

0

I found the problem, as I was accessing another domain I had to add the following lines to a .htaccess file

    Header set Access-Control-Allow-Origin "*"

Json was also incorrect, the correct one is as below:

{"success":true, "data":"00-3A"}
    
10.12.2018 / 01:24