首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >转角2柱形到外部连杆

转角2柱形到外部连杆
EN

Stack Overflow用户
提问于 2016-07-14 06:08:29
回答 1查看 3.6K关注 0票数 1

我是新的角2。它似乎是天狼星,但我需要发送form到外部链接,而且,我需要重定向用户到这个页面后,张贴请求.

代码语言:javascript
复制
<form id="Form" method="post" action="http//somelink.com" target="TheWindow">
    <input type="hidden" name="linkname" value="someValue" />
</form>

在我向JQuery提出这样的请求之前:

代码语言:javascript
复制
<script>
    $( document ).ready(function() {

        $( ".btnUpgrade" ).on( "click", function(){
            window.open('', 'TheWindow');
            document.getElementById('Form').submit();
        });

    });
</script>

但是现在我被困住了,不知道如何用角度2来做这个。我读了很多话题,但它们都是无助的。我试过window.location.href = '...';,但它只适合Get请求,对post没用。任何帮助都很感激。

更新我尝试过的(在服务中):

代码语言:javascript
复制
submitHiddenForm() {
    var headers = new Headers();
    headers = this._httpClient.createCustomHeader();
    var url = 'http//somelink.com';
    var body = 'linkname=someValue';
    return this.http.post(url, body, headers).map(this.extractData).catch(this.handleError);
}

构成部分:

代码语言:javascript
复制
submitHiddenForm() {
    this._upgradeService.submitHiddenForm().subscribe (data => {
            window.location.href = 'http://somelink.com'; },
        error => {console.log('Error while redirecting!'); });
}

我有错误:

代码语言:javascript
复制
XMLHttpRequest cannot load http://somelink.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

在我的帖子请求中,我有这样的标题:

代码语言:javascript
复制
createCustomHeader(): Headers {
    var headers = new Headers();
    headers.append('Access-Control-Allow-Origin', '*');
    headers.append('Access-Control-Allow-Headers', 'origin, x-requested-with, x-http-method-override, content-type');
    headers.append('Access-Control-Allow-Methods', 'POST');
    headers.append('Access-Control-Allow-Credentials', 'true');
    return headers;
}
EN

回答 1

Stack Overflow用户

发布于 2016-07-14 06:24:22

根据post请求的状态代码进行尝试。

代码语言:javascript
复制
this.http.request(new Request(this.requestoptions))
.subscribe(res => {
        if (res[0].status == 201) {
          this.router.navigateByUrl('..URL here..');
        }
        console.log(res[0].json);
      },
      err => {
        console.log(err);
      })
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38366652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档