当我调用login 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)
1条答案
按热度按时间sqxo8psd1#
可能重复:Chrome' Cross-Origin Read Blocking (CORB) blocked cross-origin response' ionic
不管怎样...
您需要在API响应中添加一些CORS标头。
我的后端是PHP,所以我添加了以下字符串: