@Tubiss wrote:
ı have laravel json api and works well when ı made auth in laravel post method work nice. but in ionic my codes didnt work.
this is provider
postData(credentials, type){ return new Promise((resolve, reject) =>{ let headers = new Headers({ 'Content-Type' : 'application/json' }); let options = new RequestOptions({ headers: headers }); this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers}). subscribe(res =>{ resolve(res.json()); }, (err) =>{ reject(err); }); }); }signup.ts
export class SignUpPage { resposeData : any; userData = {"full_name":"", "password":"","email":"","name":""}; constructor(public navCtrl: NavController, public authProvider:AuthProvider, public alertCtrl: AlertController , public toastCtrl:ToastController ) { } signup() { if(this.userData.full_name && this.userData.password && this.userData.email && this.userData.name){ //Api connections this.authProvider.postData(this.userData, "signup").then((result) =>{ this.resposeData = result; if(this.resposeData.userData){ console.log(this.resposeData); localStorage.setItem('userData', JSON.stringify(this.resposeData) ) this.navCtrl.push(HomePage); } else{ this.presentToast("Please give valid username and password"); } }, (err) => { console.log("error"); }); } else { console.log("Give valid information."); } } login() { this .navCtrl .push(SignInPage); } presentToast(msg) { let toast = this.toastCtrl.create({ message: msg, duration: 2000 }); toast.present(); }and when ı make auth in ionic ı am getting this error.
access to XMLHttpRequest at ‘http://…8000/api/signup’ from origin ‘http://localhost’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
so please help me.
Posts: 1
Participants: 1