Reactjs 我需要做一个;“注册”;从react前端到Scala后端api的请求
我是React.js的新手,目前正在做我的大学项目。基本上,我的注册api已经完成并且成功了,但是现在,我如何调用api来对前端做出反应呢?我已经回顾了youtube和stackoverfloe上的一些例子,但我仍然坚持在这里。下面我将详细介绍我目前的情况: 这是我在邮递员身上得到的结果。 所以我的API没有问题 以下是我如何调用API来响应前端:Reactjs 我需要做一个;“注册”;从react前端到Scala后端api的请求,reactjs,npm,axios,Reactjs,Npm,Axios,我是React.js的新手,目前正在做我的大学项目。基本上,我的注册api已经完成并且成功了,但是现在,我如何调用api来对前端做出反应呢?我已经回顾了youtube和stackoverfloe上的一些例子,但我仍然坚持在这里。下面我将详细介绍我目前的情况: 这是我在邮递员身上得到的结果。 所以我的API没有问题 以下是我如何调用API来响应前端: handleSubmit(event){ const { name, e
handleSubmit(event){
const {
name,
email,
UserMobile,
Password,
confirmPassword,
Organisation_Name,
Address,
description
} = this.state;
console.log(this.state)
axios({
method: 'post',
url: 'http://localhost:9000/api/users/sign-up',
data: {
name: name,
email: email,
UserMobile: UserMobile,
Password: Password,
confirmPassword: confirmPassword,
Organisation_Name: Organisation_Name,
Address: Address,
description: description
},
}).catch(error => {
console.log(error);
}).then(response => {
console.log(response);
});
}
以下是的一些源代码:
render() {
return (
<div>
<form onSubmit={this.handleSubmit}>
<input
type="type"
name="name"
placeholder="name"
value={this.state.name || ''}
onChange={this.handleChange}
required
/>
<input
type="email"
name="email"
placeholder="email"
value={this.state.email}
onChange={this.handleChange}
required
/>
<input
type="text"
name="UserMobile"
placeholder="UserMobile"
value={this.state.UserMobile || ''}
onChange={this.handleChange}
required
/>
<input
type="Password"
name="Password"
placeholder="Password"
value={this.state.Password || ''}
onChange={this.handleChange}
required
/>
<input
type="Password"
name="confirmPassword"
placeholder="confirmPassword"
value={this.state.confirmPassword || ''}
onChange={this.handleChange}
required
/>
<input
type="Organisation_Name"
name="Organisation_Name"
placeholder="Organisation_Name"
value={this.state.Organisation_Name || ''}
onChange={this.handleChange}
required
/>
<input
type="Address"
name="Address"
placeholder="Address"
value={this.state.Address || ''}
onChange={this.handleChange}
required
/>
<input
type="description"
name="description"
placeholder="description"
value={this.state.description || ''}
onChange={this.handleChange}
required
/>
<button type="Submit">Registration</button>
</form>
</div>
);
}
那么,react调用API是正确的方法吗?为什么我不能得到和邮递员一样的结果?新用户也不会进入数据库。希望任何人都能帮助我,教我解决这类问题 你好,好问题,祝你学习顺利。Axiis方法是否将任何内容记录到控制台?我看不出有什么错误,首先看看你的代码。您是否能够通过创建一个示例@P.BrewGood的新观点是,你的逻辑似乎没有任何问题。Axios甚至没有尝试发出网络请求,因此我认为这不是一个有效的网址。是否可以将API发布到任何位置的服务器上,或者获取运行localhost:9000的计算机的IP地址并调用该地址。所以,你不应该在学习中使用“你好,好问题,祝你好运”。Axiis方法是否将任何内容记录到控制台?我看不出有什么错误,首先看看你的代码。您是否能够通过创建一个示例@P.BrewGood的新观点是,你的逻辑似乎没有任何问题。Axios甚至没有尝试发出网络请求,因此我认为这不是一个有效的网址。是否可以将API发布到任何位置的服务器上,或者获取运行localhost:9000的计算机的IP地址并调用该地址。因此,你不应该使用
"name": "react-redux-router",
"version": "1.0.0",
"description": "Basic skeleton codebase for React/Redux/Router applications.",
"proxy": {
"/connect": {
"target": "http://localhost:9000",
"secure": false,
"changeOrigin": true
}
},