Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70752

Ionic post request save to local storage

$
0
0

@prre wrote:

Hi, i’m new with ionic and I’ve read a tutorial about making post requests.

The app is making this post request and save the data in my mysql database but if I click the “sign up” button, he don’t set the rootPage to HomePage and I’m not sure if the app save the data to the local storage because I don’t get any console.log and I don’t see any local storage in the browser.

AuthService

postData(credentials, type){

        return new Promise((resolve, reject) =>{
          let headers = new Headers();
          this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers}).
          subscribe(res =>{
            resolve(res.json());
          }, (err) =>{
            reject(err);
          });

        });

      }

SignUp:

export class SignupPage {

  responseData : any;
  userData = {"username": "","password": "", "name": "","email": ""};

  constructor(public navCtrl: NavController, public authService:AuthServiceProvider) {

   }

  signup() {
    this.authService.postData(this.userData, 'signup').then((result)=> {
      this.responseData = result;
      if(this.responseData.userData){
        console.log(this.responseData);
        localStorage.setItem('userData', JSON.stringify(this.responseData));
        this.navCtrl.setRoot(HomePage);
      }
      else{ console.log("Benutzer existiert bereits"); }
    }, (err) => {
      // Error log
    });
  }

}

Thanks for your help

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70752

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>