首页 > 解决方案 > 从 React JS Axios 调用 API POST 时值变为空

问题描述

我有一个 API TxnController,它接受参数@txnumber、@qnumber、@accountnumber、@amount、@emailaddress)。

使用此示例字符串时

{"txNumber":"1-202042121323","qNumber":65,"accountNumber":"12","amount":"12","emailAddress":""}

我能够使用 POSTMAN 保存它。

但是当我使用下面的代码使用 Axios 调用 API POST 时:

let onestr=[];
onestr=JSON.stringify(apostArray[i]);
alert(onestr);
console.log(onestr);
//alert(JSON.stringify(onestr));

axios
    .post('https://localhost:44338/api/txn/',{onestr})
    .then(response => {
        alert("POST SUCCESS "+response);
        alert("POST RESPONSE.DATA "+response.data);
    })
    .catch(error => {
        alert("POST ERROR "+error)
    })

}

我得到空值。我究竟做错了什么?

标签: mysqlreactjsapipostaxios

解决方案


推荐阅读