Error parsing JSON: Unexpected token in JSON at position

0

I have a problem with the development of an app, I saw something here like my case but they did not answer it.

This is the error:

SyntaxError: Unexpected token < in JSON at position 1
        at JSON.parse (<anonymous>)
        at Response.Body.json (http://localhost:8100/build/vendor.js:67304:25)
        at SafeSubscriber._next (http://localhost:8100/build/main.js:358:29)
        at SafeSubscriber.__tryOrUnsub (http://localhost:8100/build/vendor.js:32821:16)
        at SafeSubscriber.next (http://localhost:8100/build/vendor.js:32768:22)
        at Subscriber._next (http://localhost:8100/build/vendor.js:32708:26)
        at Subscriber.next (http://localhost:8100/build/vendor.js:32672:18)
        at XMLHttpRequest.onLoad (http://localhost:8100/build/vendor.js:67797:38)
        at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
        at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4973:33)

Code:

//funcion Registro
signup() {
//api conection

this.authServiceProvider.postData(this.userData, "signup").then((result) => {
this.resposeData = result;
console.log(this.resposeData);
localStorage.setItem('userData', JSON.stringify(this.resposeData))
this.navCtrl.push(TabsPage);

}, (err) => {})
     //connection failes message 

}


 //Provider 

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http'; 


let apiUrl ="http://localhost:8080/PHP-Slim-Restful-master/api/";

@Injectable()
export class AuthServiceProvider 
{

  constructor(public http: Http) 
  {
    console.log('Hello AuthServiceProvider Provider');
  }

  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);
        }
    })
  }

}
    
asked by Carlos Soto 07.05.2018 в 18:22
source

0 answers