使用fetch()的错误请求

时间:2018-12-05 12:34:14

标签: javascript fetch bad-request

我正在尝试使用fetch()将请求发送到服务器。但是使用此代码,我得到400(错误请求)错误。我的代码有什么问题?

$("#myLogin").click(function () {
    var username = $("input[name=username]").val();
    var password = $("input[name=password]").val();
    var person = {username : username , password : password};

    fetch("http://172.17.9.50:5000/api/v1/users/login", {
        method: "POST",
        mode: "no-cors",
        cache: "no-cache",
        credentials: "same-origin",
        headers: {
            "Content-Type": "application/json",
        },
        referrer: "no-referrer",
        body: JSON.stringify(person),
    }).then(function () {
        window.location.replace("//next page");
    }).catch(function () {

    })
});

0 个答案:

没有答案