【发布时间】:2021-10-20 20:21:56
【问题描述】:
我是 Springboot 的新手,所以我遇到了这个错误
POST http://localhost:63342/insacol/static/api/users 404(未找到)。注册用户.js:20 Uncaught (in promise) SyntaxError: Unexpected token
js代码:
// Call the dataTables jQuery plugin
$(document).ready(function() {
});
async function registerUser(){
let dates ={};
dates.name = document.getElementById('txtName').value;
dates.lastname = document.getElementById('txtLastName').value;
dates.email = document.getElementById('txtEmail').value;
dates.password = document.getElementById('txtPassword').value;
let repeatPassword = document.getElementById('txtRepeatPassword').value;
if (repeatPassword != dates.password){
alert('La contraseña es diferente');
return;
}
console.log(dates);
const request = await fetch('api/users', { method: 'POST', headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
body: JSON.stringify(dates)
const users = await request.json()
}
java代码:
@RequestMapping(value = "api/users", method = RequestMethod.POST)
public void insertUser(@RequestBody User user){
userDao.insertar(user);
}
html代码:
<a onclick="registerUser()" href="#" class="btn btn-primary btn-user btn-block">Register Usuario</a>
【问题讨论】:
-
是你的 spring boot 中定义的路径。从您分享的代码示例中很难分辨。如果您要分享一个可运行的示例会更好。
-
当您
console.log(JSON.stringify(dates)时会发生什么?格式是否正确?你确定你调用的 URL 是正确的吗? Spring boot 通过哪个端口运行?因为63342对我来说似乎有点不寻常
标签: javascript java spring spring-boot maven