您好)我正在尝试以这种方式从表单中注册用户:
const serverAddress = "http://localhost:8080";
const registerAddress = "/register";
$("#registration").submit(function () {
let registerUserDto = {
"firstName":$("#firstName").val(),
"lastName":$("#lastName").val(),
"username":$("#registerUsername").val(),
"password":$("#registerPassword").val(),
"repeatPassword":$("#repeatPassword").val()
};
$.ajax({
url: serverAddress + registerAddress,
method: 'POST',
data: JSON.stringify(registerUserDto),
contentType: "application/json; charset=utf-8",
statusCode: {
400: function () {
$("#badCredentials").text("Bad credentials");
},
201: function () {
alert("Nice!");
window.location = 'login.html';
}
}
});
});
当提交注册表单时,会触发一个函数,从字段中拉取值,将它们转换为 json 并发送到服务器。但是当我单击按钮时,会发生以下情况:
这是什么意思,如何解决?
1 个回答