В рамках этого я хочу сделать AJAX-вызов на сервер, чтобы обработать систему входа с помощью имени пользователя и пароля.
Когда я звоню, все проходит хорошо, но в ответ я получаю всю веб-страницу, и не знаю почему
Вызов Ajax (JS):
Код: Выделить всё
function AJAXfunc(username, password) {
var parameter = JSON.stringify({ "username": username, "password": password })
$.ajax({
type: "POST",
contentType: 'application/json; charset=utf-8',
url: '/Login?handler=LoginFunc',
data: parameter,
dataType: 'json',
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
success: function (data) {
onsuccess(data)
},
error: function (data, success, error) {
alert("Error: " + error + " - " + data + " - " + success + " - " + data.value)
}
})
}
Код: Выделить всё
public class LoginModel : PageModel
{
public async Task OnPostLoginFuncAsync(HttpContext http, JsonDocument json)
{
return new JsonResult("success");
}
}
Спасибо
Изменить: вот код, вызывающий функцию ajax
Код: Выделить всё
function onLoginLoad() {
const formLogin = document.getElementById("login");
formLogin.addEventListener("submit", function (event) {
const userName = formLogin.getElementsByClassName("username")[0].value;
const password = formLogin.getElementsByClassName("password")[0].value;
// stop form submission
event.preventDefault();
AJAXfunc(userName,password);
});
}
Код: Выделить всё
Login
Username
Password
Подробнее здесь: https://stackoverflow.com/questions/754 ... whole-page
Мобильная версия