javascript - 控制台日志不记录 - 它位于 js 文件的开头
问题描述
我的控制台日志没有输出任何内容。它位于 javascript 文件的开头,所以我不知道它为什么不记录任何内容。
否则我会收到 302“错误”,但我认为问题出在服务器端。
最后,ajax 帖子没有写入数据库。由于我以前从未使用过 AJAX,因此欢迎任何指针。
注意:我使用 Mikrotik 作为 HotSpot,它使用 $(美元符号)作为它自己的目的,所以我不能使用 JQuery。
感谢所有的帮助。
这是整个代码,原样......
<!DOCTYPE html>
<html>
<head>
<title>HotSpot</title>
</head>
<body>
<!-- Hotspot login form -->
<form name="hotspot" action="$(link-login-only)" method="post" id="hotspot"
$(if chap-id) onSubmit="return doLogin(); return false;" $(endif)>
<input type="hidden" name="dst" value="$(link-orig)" />
<input type="hidden" name="popup" value="true" />
<input type="hidden" name="username" type="text" value="HSuser" />
<input type="hidden" name="password" type="password" value="SimpleUserPassword" />
</form>
<!-- Mail for which gets inserted into the DB -->
<form name="mail" action="http://some.domain/validate-sanitize.php" method="post" id="mail">
<h1>Hotspot</h1>
<h2>To gain internet access, enter your email.</h2>
<br />
<input type="text" id="email" name="email" autofocus="autofocus" />
<br />
<input type="submit" value="Submit" id="submit_ok" name="submit_ok" /> <br />
</form>
<script rel="javascript" type="text/javascript">
document.getElementById("submit_ok").addEventListener("click", SendAjax);
function SendAjax() {
var email = document.getElementById("email").value;
console.log(email);
// Check if fields are empty
if (email=="") {
alert("Please enter your email.");
}
// AJAX code to submit form
else{
var xhr = new XMLHttpRequest();
xhr.open('POST', '$(link-login-only)', true);
xhr.send("dst=$(link-orig)&popup=true&username=HSuser&password=SimpleUserPassword");{
setTimeout(function(){
console.log("Fired " + email);
document.getElementById("submit_ok").submit();}, 500 );
}
}
}
</script>
</body>
</html>
解决方案
这不会回答你的问题,但它仍然会显示结果。
尝试替换console.log(email);
为alert(email);
. 您是否尝试过其他浏览器?
推荐阅读
- docker - 如何在 docker image johnnypark/kafka-zookeeper 中设置 auto.create.topics.enable=true 以便自动创建新主题?
- reactjs - react-pdf 在使用 firebase 存储时给出 CORS 错误
- python - 从 excel 文件创建数据框
- linux - ALSA 有时在重新启动后不起作用(大约 30 个中的 1 个)
- python - SMTP 出站:欺骗 ipv4 接收者来自
- angular - Angular 11 不会将文件上传到 .NET 5
- model-view-controller - MVC MapRoute 可选参数与默认值一样使用
- python - 如何使 y 轴上的数字显示以百万为单位的值,而不是 matplotlib 中的科学计数法?
- rust - 跟踪工厂及其产品之间所有权的惯用方式是什么?
- ubuntu - Ubuntu 为未连接的 WiFi 适配器应用网络计划