Node.js 将数据从angular发送到节点api
我是初学者,所以如果我的问题不相关或不容易解决,我向您道歉,但我在4天内还无法解决我的问题 我正在开发一个api,它将从angular form接收数据,然后将其与sequelize一起存储在一个mariadb表中 当我通过url提交表单,并通过api将其发布到表中时,我可以看到req.body已定义,它已到达api,但我在抛出的角度http post中出现了和错误(错误500)。 使用postman,我发现我的url无法访问,我无法确定我的错误是来自post角度,还是来自模型的后端,即使错误500是针对后端的 我试图重新定义我的sequelize模型,解析和字符串化我发送的对象,尝试其他url…但没有任何效果 这是我在提交表单时调用的函数,函数formatrequestschedulest返回我想要发布的对象Node.js 将数据从angular发送到节点api,node.js,angular,sequelize.js,Node.js,Angular,Sequelize.js,我是初学者,所以如果我的问题不相关或不容易解决,我向您道歉,但我在4天内还无法解决我的问题 我正在开发一个api,它将从angular form接收数据,然后将其与sequelize一起存储在一个mariadb表中 当我通过url提交表单,并通过api将其发布到表中时,我可以看到req.body已定义,它已到达api,但我在抛出的角度http post中出现了和错误(错误500)。 使用postman,我发现我的url无法访问,我无法确定我的错误是来自post角度,还是来自模型的后端,即使错误5
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);
return this.openDialog();
}
saveScheduledRequest(onDemandScheduledRequest: OnDemandScheduledRequest){
this.http.post('/api/ScheduledReport', JSON.stringify(onDemandScheduledRequest), {headers: {'Content-Type': 'application/json'}})
.subscribe(res=>{ console.log(res
)
console.log('ok')},
(err) =>
console.log('an error'))
/*console.log(err))*/
}
这是我的api:
var request= require('../controller/ondemandscheduledrequests');
var router = express.Router();
router.get('/getreport',request.create);
router.post('/ScheduledReport',request.create);
我也可以提供我得到的错误,但我不知道我是否可以将图片加入到问题中
我只想将表单数据存储到表中,但得到的却是错误500
使用下面的管道,然后再试一次
this.http.post('/ScheduledReport', JSON.stringify(onDemandScheduledRequest).pipe().subscribe(val => {
console.log(val, "service");
, {headers: {'Content-Type': 'application/json'}})}
请参见此处如何为您的问题添加映像:这是因为我使用路由器作为子路径,所以我的服务器配置文件中有一个应用程序。使用('/api',api)您是否在运行客户端代码(ui)时运行服务器代码(后端)