【发布时间】:2017-02-17 04:02:16
【问题描述】:
背景
Angular 2 应用程序正在我的本地主机上使用 PHP API。我知道我的 URL 端点设置正确,因为我使用 Postman 检查了它们。当我提出获取请求时,响应是我自己页面的 html。我得到一个成功代码 200 但响应错误,因为
错误
异常:JSON 中位置 0 处的意外标记
所以当我 console.log(res) 得到这个时,
// 我自己的 Angular 2 前端的 HTML。
"<!DOCTYPE html>↵<html>↵<head> etc...
我期待在回复中这样,
{
"error": true,
"api_key": false,
"message": "User is registered in our database now use update api to fill other details"
}
问题
什么会导致响应保留我发出初始请求的页面中的我自己的 html?
代码示例
我的获取请求
public checkRegister(model: LogReg) {
// Parameters obj-
let params: URLSearchParams = new URLSearchParams();
params.set('email', model.email);
params.set('email_verified', model.email_verified);
//Http request-
return this.http.get(STATICS.API_BASE + STATICS.API_LOGIN,
{ search: params }).map((res:Response) => res.json());
}
这就是我处理响应的方式,
// Login Or Register User On Our Server
this.logreg = new LogReg(profile.email_verified, profile.email);
this.checkRegister(this.logreg).subscribe((res)=>{
console.log(res);
if (profile.email_verified === false) {
console.log(res);
console.log("Check your email to verify your account!");
this.logout(this.user);
}
else if (res.profile_exist === false) {
console.log(res);
this.router.navigateByUrl('/profile');
} else if (res.profile_exist === true) {
console.log(res);
this.router.navigateByUrl('/overview');
}
});
【问题讨论】:
标签: angular