[英]method post failed to load resource the server responded with a status 404
Im new in Springboot, so im getting this error我是 Springboot 的新手,所以我收到了这个错误
POST http://localhost:63342/insacol/static/api/users 404 (Not Found).
POST http://localhost:63342/insacol/static/api/users 404(未找到)。 registerUser.js:20 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
registerUser.js:20 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
js code: 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 code:代码:
@RequestMapping(value = "api/users", method = RequestMethod.POST)
public void insertUser(@RequestBody User user){
userDao.insertar(user);
}
html code: html代码:
<a onclick="registerUser()" href="#" class="btn btn-primary btn-user btn-block">Register Usuario</a>
try to change this:尝试改变这一点:
@RequestMapping(value = "api/users", method = RequestMethod.POST)
public void insertUser(@RequestBody User user){
userDao.insertar(user);
}
with this:有了这个:
@RequestMapping(value = "insacol/static/api/users", method = RequestMethod.POST)
public void insertUser(@RequestBody User user){
userDao.insertar(user);
}
The problem should be related to the URL you invoke;问题应该和你调用的URL有关;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.