首页 > 解决方案 > 成功登录时更改窗口位置

问题描述

在此处输入图像描述

您好,我正在尝试通过从 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();

标签: javascriptxmlhttprequest

解决方案


推荐阅读