Angular 中的 HTTP POST 2

HTTP POST in Angular 2

我在 angular 2 中 posting 数据时遇到问题。

postOrder() {

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');

    let data=JSON.stringify({
                          customer_id: this.cusid,
                          mode_code: this.data2code,
                          order_totalpayment: this.dataprice,
                          order_status: this.status,
                          order_remarks: this.remarks,
                          order_type: this.ordertype
                        });


  this.http.post('http://JSON-API',data,headers)
  .map(res => res.json())
  .subscribe(res => {
  console.log("Success Order No.: "+res);
  this.ordernum = res;
  });

        let data2=JSON.stringify({
                        order_no: this.ordernum,
                        prod_id: this.dataid,
                            order_product_quantity: this.quantity,
                            order_subtotal: this.dataprice
                            });

  this.http.post('http://JSON-API',data2,headers)
  .map(response => response.json())
  .subscribe(response => {
  console.log("Order List No.: "+response);
  console.log(this.ordernum);
  });

}

我的问题是我无法 post res 数据,但是当我使用控制台日志时,它显示了正确的数据。我所做的是将 res 数据传递给 ordernum 变量。

this.http.post('http://JSON-API',data,headers)
      .map(res => res.json())
      .subscribe(res => {
      console.log("Success Order No.: "+res);
      this.ordernum = res;
      });

然后我试图 POST 它到 order_no 我的 JSON API.

let data2=JSON.stringify({
                        order_no: this.ordernum,
                        prod_id: this.dataid,
                            order_product_quantity: this.quantity,
                            order_subtotal: this.dataprice
                            });

正确的数据显示在控制台中,但在我的 JSON API 中,order_no 始终为零。除了 order_no.,我 POST 的所有数据都有效。我该怎么做才能解决这个问题。希望您能够帮助我。提前谢谢你。

this.ordernum 未定义,除非第一个 http post 已解析,将第二个 http post 放入订阅函数中以获取它:

 this.http.post('http://JSON-API',data,headers)
  .map(res => res.json())
  .subscribe(res => {
      console.log("Success Order No.: "+res);
      this.ordernum = res;
      let data2=JSON.stringify({
                        order_no: this.ordernum,
                        prod_id: this.dataid,
                            order_product_quantity: this.quantity,
                            order_subtotal: this.dataprice
                            });
      this.http.post('http://JSON-API',data2,headers)
      .map(response => response.json())
      .subscribe(response => {
          console.log("Order List No.: "+response);
          console.log(this.ordernum);
      });
  });