I am trying to prompt user for input on the client, then check if the input is valid on the server. If the input is invalid the client should re-prompt until it receives a valid input. Only once the input is valid should anything else proceed.
客户。
while(looping){
temp_name = prompt(usr + err_msg + pmsg, "");
socket.emit("is_valid", temp_name, (response) => {
looping = !response.status
err_msg = response.message
});
}
服务器。
// check if username is valid
socket.on("is_valid", (temp_name, callback) => {
// init
let msg = "";
let stat = false;
// (check if valid)
// return
stat = (msg == "")
response = {
status: stat,
message: msg,
}
callback(response);
});
My code works if I remove the while loop in 客户。. But if I add the while loop, nothing works. No log statements print either.
虽然存在漏洞,因为如果投入无效,我希望再次促使用户使用。
为什么发生这种情况?
谢谢。
我期望它回头来,看上去的是假名是否有效。
If it is valid, looping = false and it should exit the while loop. If it is invalid, looping = true and it will prompt the user again. Currently all it does it repeatedly prompt the user no matter what is entered. But if I remove the while loop, it works correctly and returns the values I expect.