【发布时间】:2019-02-21 16:40:14
【问题描述】:
当我调用登录 api 时,我收到 跨域读取阻止 (CORB) 阻止跨域响应 使用 MIME 类型 application/json 并且我无法验证用户每当我尝试登录用户时,CORB 都会阻止我的 http 请求,我无法验证用户身份。我是 ionic 新手,所以我无法解决此错误,任何帮助将不胜感激
if (this.plugins.isOnline()) {
if (this.wait == true) {
return;
} else if (this.userLogin.email == '' || this.userLogin.password == '') {
this.utility.doToast("Please don't leave any field blank.");
return;
} else {
this.wait = true;
// this.getRequiremensts();
this.auth.login(this.userLogin).subscribe((success) => {
this.wait = false;
console.log("loginData",success.successData);
this.credential.setUser(success.successData);
// this.plugins.sendTags(success.successData.id);
this.rememberUsertype(success.successData.is_celebrity);
if(success.successData.is_celebrity == '0'){
this.app.getRootNav().setRoot("HomePage");
}
else if(success.successData.is_celebrity == '1'){
this.app.getRootNav().setRoot("DashboardPage");
}
}, (error) => {
console.log(error);
this.wait = false;
if (this.utility.timeOutResponse(error))
this.utility.doToast("The email or password you entered is incorrect.")
})
}
} else {
this.utility.doToast(this.utility.internetConnectionMessage());
}
login(params) {
var url = this.constants.API_ENDPOINT + 'login';
var response = this.http.post(url, params, {}).map(res => res.json());
return response;
}
if (options == null) {
options = new RequestOptions();
}
if (options.headers == null) {
options.headers = new Headers();
}
options.headers.append('app_key', 'Some App Key');
var _token = localStorage.getItem('token');
if (_token)
options.headers.set('session_token', _token);
options.headers.set("Cache-Control", "no-cache");
return options;
}
错误
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Response.Body.json (http.js:1091)
at MapSubscriber.project (auth.service.ts:29)
at MapSubscriber._next (map.js:79)
at MapSubscriber.Subscriber.next (Subscriber.js:93)
at CatchSubscriber.Subscriber._next (Subscriber.js:129)
at CatchSubscriber.Subscriber.next (Subscriber.js:93)
at TimeoutSubscriber.Subscriber._next (Subscriber.js:129)
at TimeoutSubscriber._next (timeout.js:132)
at TimeoutSubscriber.Subscriber.next (Subscriber.js:93)
【问题讨论】:
标签: angular ionic-framework ionic2 ionic3