【发布时间】:2021-02-02 04:05:09
【问题描述】:
我想使用JS异步函数重定向到另一个页面,但是它不起作用。
以下是我的代码:
var myAccount = document.getElementById("account1");
var myPwd = document.getElementById("pwd");
async function validate_form(){
this.redirectUrl = await eel.sign_in(myAccount.value, myPwd.value)();
console.log('rendering page...,redirectUrl:'+this.redirectUrl);
window.location.replace(this.redirectUrl);
}
我尝试了另一种方法,但仍然失败
async function validate_form(){
this.redirectUrl = await eel.sign_in(myAccount.value, myPwd.value)();
console.log('rendering page...,redirectUrl:'+this.redirectUrl);
try{
await Promise.all([window.location.replace(this.redirectUrl)]) ;
}
catch (error){
// Check for login session
const response = Object.assign({}, error);
if (response.response.status === 401 || response.response.status === 401) {
alert(response);
}
}
}
命令await eel.sign_in(myAccount.value, myPwd.value)() 将获得值home.html。
有谁知道如何解决这个问题?
谢谢
【问题讨论】:
-
eel.sign_in函数有什么作用? -
validate_form函数在哪里被调用? -
@Shuvo 这个函数是关于从python中获取值的,我又编辑了这个。
-
@FortuneEkeruo 一个按钮会在html中触发
validate_form -
@Ming,我不明白你为什么要在这里使用
async?
标签: javascript asynchronous redirect