简体   繁体   English

http.delete 在 Postman 上工作正常,但在 Angular 4/Ionic 3 应用程序上无效

[英]http.delete works fine on Postman but not on Angular 4/Ionic 3 app

I ma beginner in Angular 2/Spring boot stack, so please bear with me a bit.我是 Angular 2/Spring 引导堆栈的初学者,所以请耐心等待。

I have created an http.delete method for deleting a particular row selected by the user which prompts an Alert to verify the deletion, my request actually works fine on Postman as I could delete a selected row based on the params given completely from the database, but not in my frontend app, so my API works well as intended.i even checked for Subscribe since Observable are lazy, I did several combinations of code but here's the actual Angular code:我创建了一个http.delete方法来删除用户选择的特定行,它会提示警报来验证删除,我的请求实际上在 Postman 上工作正常,因为我可以根据数据库中完全给出的参数删除所选行,但不是在我的前端应用程序中,所以我的 API 可以正常工作。我什至检查了订阅,因为 Observable 是懒惰的,我做了几种代码组合,但这是实际的 Angular 代码:

IncidentService.ts:事件服务.ts:

supprimerIncident(incident)
{
  let cHeaders = new Headers({ 'Content-Type': 'application/json' });
   let cParams = new URLSearchParams();
   cParams.set('rfcnumber',incident);
   let options = new RequestOptions({ headers: cHeaders, params: cParams })
   return this.http.delete(Api+'delete',options)

     }

And here's the code for the incident.ts file calling this service.这是调用此服务的event.ts文件的代码。

    deleter(incident:string)
  {
    let alert = this.alertCtrl.create({
        title: 'Confirmation',
        message: 'Voulez-vous supprimer ce ticket ?',
        buttons: [{
          text: "Ok",
          handler: () => { 

              this.incserv.supprimerIncident(incident).
             map(res=>res.status)
              .subscribe(res=>
  {
      for(let i = 0; i < this.incidents.length; i++) {

            if(this.incidents[i] == incident){
               this.incidents.splice(i, 1);

              }
  }
    //console.log(this.incidents=incident);

    console.log(res)
   },
    err=>{
  console.log(err);

  return Observable.throw(err.status);
  });
            }
        }, {
          text: "Annuler",
          role: 'cancel'
        }]
      })
      alert.present();


  }

The splice method works and deletes the intended row from the list, but when I run the app again, the row is back there, it's still in the database, can be deleted directly from Postman, but not the app. splice方法起作用并从列表中删除预期的行,但是当我再次运行该应用程序时,该行又回到了那里,它仍在数据库中,可以直接从 Postman 中删除,但不能从应用程序中删除。 I appreciate your help and time given, thank you very much.感谢您的帮助和时间,非常感谢。

Edit: here's the screenshot for the request network (xhr request result)编辑:这是请求网络的屏幕截图(xhr 请求结果)

在此处输入图片说明

I solved it, it was the params of the search , i changed the code from我解决了它,这是搜索的参数,我将代码从

supprimerIncident(incident)
{
  let cHeaders = new Headers({ 'Content-Type': 'application/json' });
   let cParams = new URLSearchParams();
   cParams.set('rfcnumber',incident);
   let options = new RequestOptions({ headers: cHeaders, params: cParams })
   return this.http.delete(Api+'delete',options)

     }

to :到:

supprimerIncident(incident)
{
  let cHeaders = new Headers({ 'Content-Type': 'application/json' });
   let cParams = new URLSearchParams();
   cParams.set('rfcnumber',incident.rfcnumber);
   let options = new RequestOptions({ headers: cHeaders, params: cParams })
   return this.http.delete(Api+'delete',options)

     }

"incident" was what returning the [object Object] , i did put a JSON.stringify to verify its content, it held the whole request,wherea i wanted just the rfcnumber as a param for the search for the deletion. “事件”是返回 [object Object] 的内容,我确实放置了一个 JSON.stringify 来验证其内容,它保存了整个请求,而我只想将 rfcnumber 作为搜索删除的参数。

Hope it helps anyone having a similar issue希望它可以帮助任何有类似问题的人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM