【发布时间】:2015-05-03 11:40:37
【问题描述】:
如果我没有使用正确的术语,请提前道歉。 我得到了一个简单的 sinatra api 来处理用户和组。 我一直在研究这一切的逻辑,虽然一切似乎都在工作,但我无法通过 onclick 调用 issuccess 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>
【问题讨论】:
标签: javascript jquery html api sinatra