Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从java脚本调用rest api post服务引发错误_Javascript_Java_Html_Spring Boot_Spring Mvc - Fatal编程技术网

Javascript 从java脚本调用rest api post服务引发错误

Javascript 从java脚本调用rest api post服务引发错误,javascript,java,html,spring-boot,spring-mvc,Javascript,Java,Html,Spring Boot,Spring Mvc,在控制台中从java脚本调用post服务时,我得到以下错误 加载资源失败:服务器响应状态为415() 在我的后端JavaEclipseIDE中出现了以下错误 内容类型为“文本/普通”;字符集=UTF-8'不受支持 如何解决此错误 提前谢谢 HTML代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <met

在控制台中从java脚本调用post服务时,我得到以下错误

加载资源失败:服务器响应状态为415()

在我的后端JavaEclipseIDE中出现了以下错误

内容类型为“文本/普通”;字符集=UTF-8'不受支持

如何解决此错误

提前谢谢

HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/index.css" />
    <title>Document</title>
</head>
<body>
    <div>
        <h1 class="myclass">HELLO!WELCOME</h1>
    </div>
    <div>
        <form id="loginform" method="post">
            <div class="form-group">
                <input type="number" class="form-control" id="inputphone" placeholder="Enter phone number">
            </div>
            <div class="form-group">
                <input type="password" class="form-control" id="inputpassword" placeholder="Enter Password">
            </div>
            <div class="forgot-password">
                <a href="">forgot password</a>
            </div>
           <input type="submit"value="Login"/>
        </form>
    </div>
    <script src="js/index.js"> </script>    
</body>
</html> 

你能分享后端代码吗?我的后端代码工作正常,而rest clientok的调用可能是这是问题的主体:JSON.stringify({jdata})应该是:JSON.stringify(jdata)是的,我尝试过,但没有使用相同的错误你不能使用
内容类型:application/JSON;charset=UTF-8
具有
模式:“无COR”
,改为发送
文本/普通
,后端拒绝发送。请参阅和。您能否共享后端代码我的后端代码工作正常,而来自rest clientok的调用可能是这是问题正文:JSON.stringify({jdata})应该是:JSON.stringify(jdata)是的,我尝试过,但没有使用相同的错误您不能使用
内容类型:application/JSON;charset=UTF-8
具有
模式:“无COR”
,改为发送
文本/普通
,后端拒绝发送。见和。
var form = document.getElementById('loginform')

form.addEventListener('submit', function (e) {

    e.preventDefault();

    var inputphoneno = document.getElementById("inputphone").value;
    var inputpassword = document.getElementById("inputpassword").value;
    
    const jdata = {
        "phonenumber":inputphoneno,
        "password":inputpassword
      };

    fetch('http://localhost:8080/myurl/', {
        method: 'POST',
        body: JSON.stringify({jdata}),
        headers: {
            'Content-Type': 'application/json; charset=UTF-8',
        },
        mode: "no-cors"
    })
        .then(function (response) {
            //return response.json();
            console.log(response)
        })
        .then(function (data) {
            console.log(data)
        })

})