javascript - 控制台日志不是日志记录 - 它位于 js 文件的最开头

标签 javascript html ajax

我的控制台日志没有输出任何内容。它位于 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);。 您是否尝试过其他浏览器?

关于javascript - 控制台日志不是日志记录 - 它位于 js 文件的最开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59453467/

相关文章:

javascript - 主干忽略 idAttribute 并设置自己的

html - 一行中可以并排放置 2 张背景图片吗?

html - :hover background with img inside

jquery - 内嵌 facebook 和 google + 按钮的位置?

javascript - $(document).ready 和 $ ('#id' ).change 产生不同的结果

JavaScript:相对于父级单击时增加变量值

javascript - 使用 lodash.groupBy() 标准化对象

javascript - 如何获取div的类名?

javascript - 使用 Javascript 生成占用的 DIV

javascript - ajaxComplete 多次触发 - woocommerce 添加到购物车