如何修复错误415

时间:2016-09-20 06:47:36

标签: html mongodb

我的html有问题。我从Eclipse运行我的html并尝试输入“电话号码”和“密码”。两个数据都成功输入为json。我打算将我的html直接连接到mongodb并存储我的数据。但是错误415出来了,我不知道如何解决它。

这是我的html:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login</title>

<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="bootstrap.css">

<!-- <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> -->
<script src="jquery-3.0.0.min.js"></script>
<script src="login.js"></script>

</head>
<body>
<nav class="navbar navbar-default">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">Login</a>
    </div>
    </nav>

    <div class = "container">
    <form>
  <div class="form-group">
    <label for="exampleInputEmail1">No Telpon</label>
    <input type="text" class="form-control" id="notelpon" placeholder="No Telpon">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="password" placeholder="Password">
  </div>

</form>
 <button id="SubmitBtn" type="submit" class="btn btn-default">Submit</button>
</div>
</body>

</html>

这是我的js:

$( document ).ready(function() {
    $("#SubmitBtn").click(function(){
        submit();
    });
});

function submit(){

    var submitcoy = {
        notelpon : $("#notelpon").val(),
        password : $("#password").val(),
    };

    var submitjson = JSON.stringify(submitcoy);
    console.log(submitcoy); 

    $.ajax({
          url: "/BankSinarmas/submit",
          context: document.body,
          type: 'POST',
          data: submitjson,
          contenttype: 'application./json',
        }).done(function(response) {
            console.log(response);
        });
}

错误是:POST(我的本地主机)415() 谢谢你,祝你有个美好的一天。

1 个答案:

答案 0 :(得分:0)

来自HTTP / 1.1规范的status code section

  

415不支持的媒体类型

     

服务器因为实体而拒绝为请求提供服务   请求采用所请求资源不支持的格式   要求的方法。

使用无效的Content-Type HTTP标头会发生这种情况。 JSON的正确MIME媒体类型是application/json。当您发现Ajax请求时,属性名称需要contentType