无法使用post方法调用服务

时间:2019-05-20 08:26:21

标签: angular typescript

使用邮递员,我可以呼叫服务,但不能从角度做到这一点。

下面是我的7号打字稿中的脚本

   save() {
   this.sales.detail=this.empList;

   let httpHeaders = new HttpHeaders({
    'Content-Type' : 'application/json'
     });    
     let options = {
    headers: httpHeaders
     };     
     let body = JSON.stringify(this.sales);     
     this.http.post(this.baseUrl + 'api/Sales/Order/', body, options).subscribe((res)=>{
        console.log("Updated the customer");
     });


}

邮递员脚本是

var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:9220/api/Sales/Order",
"method": "POST",
"headers": {
   "content-type": "application/json",
   "cache-control": "no-cache",
   "postman-token": "4c5861cf-be10-6a46-0b77-27d862d9799f"
 },
"processData": false,
 "data": "{mydata}"

 $.ajax(settings).done(function (response) {
console.log(response);
 });

1 个答案:

答案 0 :(得分:0)

尝试一下:

this.http.post(this.baseUrl + 'api/Sales/Order', body).subscribe((res)=>{
    console.log("Updated the customer");
});