与Firefox的角2 POST [英] Angular 2 POST with Firefox

查看:155
本文介绍了与Firefox的角2 POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来Angular 2和我的应用程序,IE浏览器和铬工作正常。但是,当我尝试在Firefox中调用我的PHP脚本的发布请求在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});

返回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代码似乎是正确的...



本文可能会引起您的兴趣: b http://restlet.com/blog/2015/12/10/understanding-http-content-negotiation/

I am new to Angular 2 and my application that works fine with IE and chrome. However, when I try in Firefox the post request that calls my PHP script does not work within 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)
}

解决方案

It seems that the value of your Accept header isn't correct. Perhaps it's the reason of your problem on Firefox.

You could try the following:

headers.append('Accept', 'application/json;q=0.9,*/*;q=0.8');

Otherwise, your Angular2 code seems correct...

This article could interest you:

这篇关于与Firefox的角2 POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆