Javascript html5表单提交到onclick js函数:什么都没有发生

Javascript html5表单提交到onclick js函数:什么都没有发生,javascript,jquery,html,api,sinatra,Javascript,Jquery,Html,Api,Sinatra,如果我没有使用正确的术语,请提前道歉。 我得到了一个简单的sinatra api,可以与用户和组一起工作。 我一直在研究这一切的逻辑,虽然一切似乎都在运行,但我无法让onclick调用issucess js函数。我试着做事件侦听器。我现在迷路了,请帮帮我 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML5 Login</titl

如果我没有使用正确的术语,请提前道歉。 我得到了一个简单的sinatra api,可以与用户和组一起工作。 我一直在研究这一切的逻辑,虽然一切似乎都在运行,但我无法让onclick调用issucess js函数。我试着做事件侦听器。我现在迷路了,请帮帮我

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>HTML5 Login</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <section class="loginform cf">
        <form name="login" method="post" onclick="return isSuccess()" accept-charset="utf-8">
            <ul>
                <li>
                    <label for="usermail">Email</label>
                    <input type="email" name="usermail" placeholder="yourname@email.com" required>
                </li>
                <li>
                    <label for="password">Password</label>
                    <input type="password" name="password" placeholder="password" required></li>
                <li>
                    <input type="submit" value= "login" \>
                </li>
            </ul>
        </form>
    </section>

    <script type="text/javascript">
    function isSuccess(){
        var firstAdmin = {
            "name": "Admin",
            "email": "admin@example.com",
            "password": "secret",
            "admin": true
            };
        $.post("main.rb", firstAdmin);

        function isValidUser() {
            $.get( "/users", function(data) {
                var x=document.form.usermail.value;
                var y=document.form.password.value;
                if (x === users.email && y === users.password && users.admin === true){
                    window.location="userprofile/adminprofile.html";
                }
                if (x === users.email && y === users.password && users.admin === false){
                    window.location="userprofile/userprofile.html";
                }
            alert( "success" );
            })



            });
        }
    }
    </script>
</body>
</html>

HTML5登录
  • 电子邮件
  • 密码
函数isSuccess(){ var firstAdmin={ “名称”:“管理员”, “电子邮件”:admin@example.com", “密码”:“秘密”, “管理员”:正确 }; $.post(“main.rb”,firstAdmin); 函数isValidUser(){ $.get(“/users”,函数(数据){ var x=document.form.usermail.value; var y=document.form.password.value; if(x==users.email&&y==users.password&&users.admin==true){ window.location=“userprofile/adminprofile.html”; } if(x==users.email&&y==users.password&&users.admin==false){ window.location=“userprofile/userprofile.html”; } 警惕(“成功”); }) }); } }
我认为您没有正确使用
$get
。你查过文档了吗

目前,您在执行以下操作时忽略了get的结果:

if ($.get('/users') = 200){
因为该函数立即返回(无论Sinatra API请求是否已完成)。您需要传入一个回调函数,该函数将在请求实际完成后的某个时间立即调用:

$.get( "/users", function(data) {
  //automatically get here if return status is 200
  alert( "success" );
})

谢谢你的帮助!!:)