As i was using ionic3 procject working and still apk working well . Ionic auto v4 updated and now i get this error " Unexpected end of JSON input"
i using mysql beckend
i changed ionic version 4 to 3.4 , but still i get same error. how can fix it
I unable to solve it ,anyone know please teach me i will appreciate~
login.ts
login(){
if(this.userData.username && this.userData.password){
this.authService.postData(this.userData, "login").then((result) =>{
this.resposeData = result;
auth.service.ts
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);
});
});
}
anyone help me. i am very misarable
Try adding the debugger line. Run it in a browser and see what is contained in the res variable to give you an idea.
return new Promise((resolve, reject) =>{
let headers = new Headers();
this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers}).
subscribe(res =>{
debugger; <--
resolve(res.json());
}, (err) =>{
reject(err);
});
});
Unsubscribe error.
What do you think it might be causing an error
Server is rejecting your auth attempt I think
I fix the unexpected end of json input problem. no need of promise with v4 but another problem occurred.
If i start project on development mod on web or mobile i get this error
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://katalog.forev.com.tr/PHP-Slim-Restful-master/api/login with MIME type text/html. See Chrome Platform Status for more details.
I used chrome extension allow control allow origin but it didnt work
And my php beckend sql header conf.
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers " content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
There was no such error in the ioniv v3
I generate android apk and try on apk, no error . work well. i really understand.
Podum
May 24, 2019, 5:40pm
8
This is googles doing. It’s a new security feature added to the browser. Trust me your ionic 3 projects will go through the same thing when served on the browser.
At some point in time during your development your machine updated your chrome browser to 67+ (I think 73 is when they literally just start blocking json altogether). And this version is where the CORB or cross-origin read blocking feature starts.
I’m still trying to figure out a way around this but hopefully, the angular team may have an answer soon (At least ionic 4 can be saved).