我想使用nodejs API将数据插入SQL Server数据库中,但是无法从react-native发送数据。我尝试使用axios.post
和提取方法无法将数据发送到Web API,但我做不到。我究竟做错了什么?你能帮我吗?
这是我的NODE JS WEB API:
app.post("/insert", function(req, res) {
(async function insert(ProName,ProDesc,OnDate) {
try {
let pool = await sql.connect(sqlConfig);
const request= pool.request();
request.input("ProName", sql.VarChar, ProName)
request.input("ProDesc", sql.VarChar, ProDesc)
request.input("OnDate", sql.VarChar, OnDate)
request.query('INSERT INTO Producttbl
(ProName,ProDesc,OnDate) VALUES(@ProName,@ProDesc,@OnDate)',
反应本机代码:
state = {ProName:'',ProDesc:'',OnDate:''};
insert= () =>{
const {ProName,ProDesc,OnDate}=this.state;
axios({
method: 'post',
url: 'url/insert',
data: {
ProName,
ProDesc,
OnDate
},
}).then(response =>
this.setState({
ProName:response.ProName,
ProDesc:response.ProDesc,
OnDate:response.OnDate
});
})
<TextInput onChangeText={(ProName)=>this.setState({ProName})} />
JSON:
https://i.stack.imgur.com/zEwn2.png