Axios post表单提交,reactjs localhost - 404错误状态



我想在我的localhost reactjs表单上测试post请求。表单我们提交后,我想重定向到另一个页面,我张贴的形式。现在我得到404错误,我正在尝试不同版本的axios代码示例,但到目前为止没有任何工作。

这是我的post函数

const formData = {
description: description,
netto: netto,
brutto: brutto,
vat: vat
};
function handleSubmit() {
axios.post(
"/FormSubmit",
{
description: description,
netto: netto,
brutto: brutto,
vat: vat
},
{
headers: {
"Content-type": "application/json; charset=UTF-8",
}
}
)
.then((response) => {
if (response.status == 200) alert("Login Success");
})
.catch((error) => {
console.log(error);
});
};

这是我的表格

return(
<form action='/FormSubmit' id='form' onInvalid={handleEmptyDescription}>
<div className="vertical-space">
<label>Description </label>
<textarea id='descr' type='text'
value={description}
onChange={handleDescriptionChange}
maxLength='25'
required/>
<span> {wordCounter}/255</span>
</div>
<div>
<label>Send confirmation</label>
<input  type='radio' name='radio' required />
<span>YES</span>
<input  type='radio' name='radio' required />
<span>NO</span>
</div>
<div className="vertical-space">
<label>VAT </label>
<select value={vat} onChange={handleVatChange} required>
<option value="" disabled defaultValue >Choose VAT</option>
<option value="1.19">19%</option>
<option value="1.21">21%</option>
<option value="1.23">23%</option>
<option value="1.25">25%</option>
</select>
</div>
<div className="vertical-space">
<label>Price netto EUR </label>
<input id='netto' pattern="d+((.|,)d+)?" disabled={nettoDisabled} type='text'
value={netto}
onChange = {handleNettoChange}
onKeyUp = {handleWrongInput}
required/>
</div>
<div>
<span id='wrongInput' className='hiddenMessage messageStyle'> Please, input number</span>
</div>
<div className="vertical-space">
<label>Price brutto EUR </label>
<input id='brutto' value={brutto} disabled type='text'/>
</div>
<button onClick={handleSubmit} type='submit'>Submit</button>
</form>
)
}

axios.post("/FormSubmit",{描述:formData.description,最低:formData.netto,毛重:formData.brutto,增值税:formData.vat},

相关内容