angular - 在角度/节点中将数据从 api 发布到
问题描述
如果我的问题是多余的,我很抱歉,但我已经尝试解决这个问题了 2 天。
我有一个 angular at 表格localhost:4000
,我想将它的数据发布到我的 api,localhost:4000/api/scheduled
但每次我得到一个 500 错误。
然后这些数据可能会从 api 发送到 mariadb。我可以实现从 mariadb 到 angular 的获取请求,但 post 不起作用。
我精确它,但我认为将表单从角度发布到 api 的错误。
我尝试了很多东西,比如调整标题,通过缩小发送的数据......但没有任何效果。
onSubmitScheduled() {
let OndemandScheduledRequest = this.formatRequestScheduled(this.selectedHotel, this.selectedCheckInDate, this.selectedCheckOutDate, this.selectedNumber, this.selectedCurrency, this.selectedReportName, this.selectedUser, this.selectedEmail, this.selectedFormat);
console.log(OndemandScheduledRequest);
this.saveScheduledRequest(OndemandScheduledRequest);
this.openDialog();
}
saveScheduledRequest(onDemandScheduledRequest: OnDemandScheduledRequest) {
console.log(onDemandScheduledRequest);
/* var headers = new HttpHeaders();
headers.append('Content-Type', 'application/form-data');
*/
return this.http.post('http://localhost:4000/api/scheduled',onDemandScheduledRequest )
.subscribe(
response => {
debugger;
console.log(response)
},
(err : HttpErrorResponse)=> console.log({
err
},))
}
这是发布在界面中定义的对象(我已导入)的函数:
export interface OnDemandScheduledRequest {
id: string,
user: string,
email: string,
reportName: string,
format: string,
submissionDate: string,
Name: string,
checkIn: string,
checkOut: string,
guests: string,
currency: string,
status: boolean,
}
这是使用表单字段创建此接口实例的函数:
formatRequestScheduled(selectedHotel, selectedCheckInDate, selectedCheckOutDate, selectedNumber, selectedCurrency, selectedReportName, selectedUser, selectedEmail, selectedFormat ) :
//AS MANY RESULTS AS REQUESTED HORIZONS.
any{
let DemandScheduledRequest = {
id: '1',
user: selectedUser.toString(),
email: selectedEmail.toString(),
reportName: selectedReportName.toString(),
format: selectedFormat.toString(),
submissionDate: new Date(),
Name: selectedHotel.toString(),
checkIn: selectedCheckInDate,
checkOut: selectedCheckOutDate,
guests: selectedNumber.toString(),
currency: selectedCurrency.toString(),
status: false,
}
return DemandScheduledRequest;
}
感谢您的任何帮助。
解决方案
推荐阅读
- python - Python - 使用 Pandas 将 JSON 转换为 CSV
- javascript - ReactJS 中的 npm debounce 失败
- python-3.x - Scrapy Next Page没有重定向
- python - 在一个新类中,如何避免调用另一个类的实例?
- angularjs - 在圆圈内设置文本样式
- android - ArCore Sceneform:检测图像时播放 .mp4 视频
- ruby - 如何在创建方法中添加记录以加入表?
- angular - 为什么向列标题添加工具提示会导致角度列侧向跳跃?
- java - Java - 等于列表返回假?
- angular - ngSwitch 中的@ViewChild 未定义