@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