【问题标题】:request http.put don't excute请求 http.put 不执行
【发布时间】:2019-09-18 05:48:52
【问题描述】:

我使用了 http.get 和 http.post,我得到了他们的回应,但是当我尝试 http.put 时没有结果 ( "返回 this.http.put(this.apiUpdate, data, httpOptions) " 问题出在这里我不知道为什么它不执行它;但是它可以在后端运行,我已经对其进行了测试,

enter code here

 apiUpdate: '*********/*****/update';

   public update-client(data: Client) {
   console.log("client: ",data);
  const httpOptions = {
    headers: new HttpHeaders({
    'Content-Type': 'application/json'
  })
     };

    // let options = new HttpRequestOptions({ headers: headers });


   console.log("service");
     return this.http.put(this.apiUpdate, data, httpOptions);
  }

【问题讨论】:

标签: typescript ionic3


【解决方案1】:

此请求是可观察的,这意味着它需要“启动”才能执行任何操作。为此,您需要订阅 observable,这可以使用

this.http.put(this.apiUpdate, data, httpOptions).subscribe(result => {  ...  }); 

这样做可以让您从发布请求中获取结果,并在 {} 中做任何您想做的事情。您也可以捕获错误。

更多信息应该可以在这里找到:https://angular.io/tutorial/toh-pt6

【讨论】:

  • 我已经完成了,我已经在我的页面上订阅了 .ts updateAccount() { console.log("pressed"); this.data = { id: this.idClient, firstname: Firstname, lastname: Lastname, nbcnss: Nbcnss }; this.clientServiceProvider.updateClient(this.data).subscribe((res:any) => { console.log("puttt"); console.log(res); this.navCtrl.setRoot(HomePage); },跨度>
猜你喜欢
  • 2019-09-20
  • 2018-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多