首页 > 解决方案 > 控制台日志不记录 - 它位于 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>

标签: javascripthtmlajax

解决方案


这不会回答你的问题,但它仍然会显示结果。

尝试替换console.log(email);alert(email);. 您是否尝试过其他浏览器?


推荐阅读