我在发送邮件请求时遇到问题
//表格是模型所必需的
router.route('/').post(function(req,res,next){
res.send(req.body)
form.create(
{"first_name": req.body.first_name,
"last_name": req.body.last_name
})
.then(function(data){
res.send(data);
console.log(data);
}).catch(function(err){console.log(err)});
});
但我需要从客户那里发出,而不是postman .在这里我迷路了.我可以用它,但当我添加Submit action时,它就不起作用了.我需要使用新功能启动另一个东西,而无需重定向到另一个页面.如何通过这个.裁判.名字.值转换为body,以便我可以使用fetch函数??
添加了这个JavaScript/JSON片段
export default class Form extends React.Component {
constructor(props){
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event){
event.preventDefault();
console.log(this.refs.first_name.value);
fetch('/', {
method: 'post',
body: {
"first_name": this.refs.first_name.value
}
});
};
render () {
return (
<div id="signup">
<form onSubmit={this.handleSubmit}>
<input ref="first_name" placeholder="First Name" type="text" name="first_name"/><br />
<input placeholder="Last Name" type="text" name="last_name"/><br />
<button type="Submit">Start</button>
</form>
</div>
)
}
}