简体   繁体   English

方法 post 无法加载资源服务器响应状态 404

[英]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.

相关问题 加载资源失败:服务器响应状态为 404() - Failed to load resource: the server responded with a status of 404 () 加载资源失败:服务器响应状态为404 - Failed to load resource: the server responded with a status of 404 无法加载资源:服务器响应状态为404? 资源问题 - Failed to load resource: the server responded with a status of 404 ? Resource issue 程序无法加载无法加载资源:服务器以404(未找到)状态响应 - Program will not load Failed to load resource: the server responded with a status of 404 (Not Found) Node.js服务器:无法加载资源:服务器以状态404(未找到)响应 - Nodejs server: Failed to load resource: the server responded with a status of 404 (Not Found) Javascript XHR 向 php 文件发送请求:加载资源失败:服务器响应状态为 404(未找到) - Javascript XHR Post Request to php file: Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为 404(未找到)? - Failed to load resource: the server responded with a status of 404 (Not Found)? 加载资源失败:服务器响应状态为404(未找到) - getting Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为404()Controller.js:1 - Failed to load resource: the server responded with a status of 404 () Controller.js:1 加载资源失败:服务器响应状态为404() SpringBoot - Failed to load resource: the server responded with a status of 404 () SpringBoot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM