javascript - 成功登录时更改窗口位置
问题描述
您好,我正在尝试通过从 HTML 获取用户名和密码并检查服务器响应中的用户名 = 名称和密码 = UID 来创建登录表单。那么如果这是真的访问应该是真的,我想去窗口位置“start.html”,但我不能让它去那里。服务器工作正常。任何人都知道为什么会这样?
更新:: 如果我在 onload 函数中移动 window.location 仍然不起作用
function connection() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var request = new XMLHttpRequest();
request.open("GET", "http://localhost:8080/users?uid=" + password, true);
request.onload = function () {
// Success!
data = JSON.parse(this.response);
if (data.Nombre == username && data.UID == password) {
access = true;
}
if (access == true) {
window.location = "start.html";
}
};
request.onerror = function () {
// There was a connection error of some sort
};
request.send();
解决方案
推荐阅读
- sql-server - SQL Server 将 2 个条件合二为一
- javascript - 通过javascript隐藏来自不和谐用户的消息 - 软阻止
- javascript - 如何使用 WebSocket 处理实时通知?
- node.js - 升级到 Webpack 5 失败
- javascript - 频率上的音频 API 中心可视化
- sql - 比较 SQL 中的列值
- r - anesrake 错误:“没有变量的偏离超过 ____”
- javascript - 同步函数执行(排序算法)
- android - 如何在活动重新创建后处理 onCreate 中 Dagger 注入所需的未初始化资源?
- java - 如何在一组值上正确使用 assertThrows?