尝试通过pos

时间:2018-08-31 12:53:11

标签: javascript json

伙计

我尝试通过邮寄发送表单数据时遇到错误400的问题。 但是我找不到错误在哪里:

本地主机吗?

function sendUser() {
const form = document.getElementById("cad");
if (submit) {
  submit.addEventListener("click", function () {
    let user = new User(
      form.userProfile.value,
      form.name.value,
      form.lastname.value,
      form.email.value
    );

    fetch('http://localhost:8080/api/auth/register-user', {
      method: 'POST',
      body: JSON.stringify(user),
      headers: new Headers({
        'Content-Type': 'application/json'
      })
    }).then(function (response) {
      if (response.ok) {
        return response.json();
      } else {
        return Promise.reject({
          status: response.status,
          statusText: response.statusText
        });
      }
    }).catch(function (error) {
      console.log('Looks like there was a problem: \n', error);
    });
  })
}

}

1 个答案:

答案 0 :(得分:0)

我可以使用jquery

var settings = {
      "url": "http://10.1.2.10:8080/api/auth/register-user",
      "method": "POST",
      "headers": {
        "Content-Type": "application/json",
        "Cache-Control": "no-cache",
      },
      "data": JSON.stringify(user)
    }

    $.ajax(settings).done(function (response) {
      console.log(response);
    });