【发布时间】:2016-05-11 09:25:43
【问题描述】:
我正在使用 angular2 和 typescript。
我正在尝试发布到我的邮件黑猩猩订阅列表。
到目前为止我的代码:
constructor(router: Router, http: Http){
this.router = router;
this.http = http;
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');
this.headers.append('Access-Control-Allow-Origin', '*');
}
subscribe = () => {
var url = "https://thepoolcover.us10.list-manage.com/subscribe/post?u=b0c935d6f51c1f7aaf1edd8ff&id=9d740459d3&subscribe=Subscribe&EMAIL=" + this.email;
this.isSuccess = false;
this.http.request(url, this.headers).subscribe(response => {
console.log(response);
this.isSuccess = true;
});
}
这是我在控制台中遇到的错误:
我现在收到此错误:Uncaught SyntaxError: Unexpected token
当前代码如下:
export class Footer{
email: string = "";
router : Router;
http : Http;
jsonp: Jsonp;
isSuccess: boolean = false;
constructor(router: Router, jsonp: Jsonp, http: Http){
this.router = router;
this.http = http;
this.jsonp = jsonp;
}
subscribe = () => {
var url = "https://thepoolcover.us10.list-manage.com/subscribe/post?u=b0c935d6f51c1f7aaf1edd8ff&id=9d740459d3&subscribe=Subscribe&EMAIL=" + this.email;
this.isSuccess = false;
this.jsonp.request(url).subscribe(response => {
console.log(response);
this.isSuccess = true;
});
}
【问题讨论】:
-
我认为服务器属性中的这个问题参见:stackoverflow.com/questions/36825429/…
-
请看下面的答案:Access Control Allow origin
标签: angular angular-http