我是Angular 2的新手,我的应用程序可以很好地与IE和chrome配合使用。但是,当我在 Firefox 中尝试时,调用我的 PHP 脚本的 post 请求在 Firefox 中不起作用。
postApplicant(newApplicant: Applicant): Observable<string> {
let body = `firstName=${newApplicant.firstName}&lastName=${newApplicant.lastName}`;
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
headers.append('Accept', 'q=0.8;application/json;q=0.9');
let options = new RequestOptions({ headers: headers });
return this.http.post(this.emailUrl, body, options)
.map(res => <string> res.json())
.catch(this.handleError)
}
似乎您的Accept
标头的值不正确。也许这是您在Firefox上出现问题的原因。
您可以尝试以下操作:
headers.append('Accept', 'application/json;q=0.9,*/*;q=0.8');
否则,您的 Angular2 代码似乎是正确的......
本文可能会让您感兴趣:
- http://restlet.com/blog/2015/12/10/understanding-http-content-negotiation/