Angular 无法使用post方法调用服务
使用邮递员,我可以呼叫一个服务,但同样的,从角度看,我无法呼叫 下面是我用angular 7字体写的脚本Angular 无法使用post方法调用服务,angular,typescript,Angular,Typescript,使用邮递员,我可以呼叫一个服务,但同样的,从角度看,我无法呼叫 下面是我用angular 7字体写的脚本 save() { this.sales.detail=this.empList; let httpHeaders = new HttpHeaders({ 'Content-Type' : 'application/json' }); let options = { headers: httpHeaders };
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);
});
试试这个:
this.http.post(this.baseUrl + 'api/Sales/Order', body).subscribe((res)=>{
console.log("Updated the customer");
});
试试这个:
this.http.post(this.baseUrl + 'api/Sales/Order', body).subscribe((res)=>{
console.log("Updated the customer");
});
错误是什么?HttpErrorResponse{headers:HttpHeaders,状态:0,状态文本:“未知错误”,url:,ok:false,}错误:ProgressEvent{isTrusted:true,lengthComputable:false,loaded:0,total:0,type:“error”,…}头:HttpHeaders{normalizedNames:Map(0),lazyUpdate:null,头:Map(0)}消息:“Http失败响应:0未知错误”名称:“HttpErrorResponse”确定:错误状态:0状态文本:“未知错误”url:“proto:HttpResponseBaseFor Http,您正在使用HttpClient对吗?
从'@angular/common/Http'导入{HttpClient};
什么是错误?HttpErrorResponse{headers:HttpHeaders,状态:0,状态文本:”未知错误”,url:,ok:false,…}错误:ProgressEvent{isTrusted:true,lengthComputable:false,loaded:0,total:0,键入:“Error”,…}标题:HttpHeaders{normalizedNames:Map(0),lazyUpdate:null,标题:Map(0)}消息:“0未知错误的Http失败响应”名称:“HttpErrorResponse”ok:false状态:0 statusText:“未知错误“url:”proto:HttpResponseBaseFor http,您正在使用HttpClient对吗?从“@angular/common/http”导入{HttpClient};