html - 来自 JS 问题的 HTML FORM 重定向
问题描述
我的网站上有一个表格,每当我使用它时,都会有两种不同的行为:
-1 如果任何字段为空,它会将我重定向到预期的页面
-2 如果两个字段都填满,那么它不会将我重定向到任何地方 HTML
<div id="id01" class="modal">
<span onclick="document.getElementById('id01').style.display='none'"
class="close" title="Close Modal">×</span>
<!-- Modal Content -->
<form class="modal-content animate">
<div class="imgcontainer">
<img src="Logo_JO_d'été_-_Paris_2024.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" id="uname" required>
<label for="upsw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" id="upsw" required>
<button onClick="SendData()">Login</button>
</div>
</form>
</div>
</div>
JS
function SendData()
{
var XHR = new XMLHttpRequest();
var urlEncodedData = "";
var urlEncodedDataPairs = [];
const uName = document.getElementById('uname');
const uPswd = document.getElementById('upsw');
urlEncodedDataPairs.push(encodeURIComponent("mail") + '=' + encodeURIComponent(uName));
urlEncodedDataPairs.push(encodeURIComponent("password") + '=' + encodeURIComponent(uPswd));
urlEncodedDataPairs.push(encodeURIComponent("role") + '=' + encodeURIComponent("user"));
urlEncodedData = urlEncodedDataPairs.join('&').replace(/%20/g, '+');
XHR.open('POST', 'http://XXX.XXX.XXX.XX:XXXX/account/add');
XHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
XHR.send(urlEncodedData);
sPath = "../booking/bookingen.html"
window.location = sPath;
}
任何人都可能知道它为什么这样做?
解决方案
推荐阅读
- sql - Where...IN 条件中的 SQL 多个 ID 列
- labview - 我需要帮助更改连接到伺服电机的 LabVIEW 读取 VI 的数据采集速率
- list - Flutter 可以创建 AnimationController 列表吗?
- excel - 获取范围内最后一个非空单元格的列号(如果值不唯一)
- javascript - Next.js/React - 如何从 Apollo 客户端 HOC 普遍解析用户语言?
- security - 如何为您不信任的特定 vscode 扩展禁用 Internet 访问
- visual-studio-code - VSCode Rest客户端 - 如何将变量设置为变量
- xpages - XPages 百分比字段
- c - 代码从 C 中的文本文件中读取几行
- google-api - Google Drive API 分段上传导致文件损坏