0

我在 index.html 文件中使用 javascript 来使用另一个 javascript 表单加载登录 php 页面,如果我直接进入 login.php 页面,那么提交按钮就可以正常工作,但是一旦它加载到我的 index.html 文件中即使视觉上所有内容都已正确加载到我的屏幕上,它也不会做任何事情。

这是我的 index.html

<!doctype html>
<html>
<head>
</head>
<body>
<div id='myStyle'></div>
<script src="jquery.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $('#myStyle').load('./login.php');
});
</script>
</body>
</html>

这是 login.php 文件

<script type="text/javascript" src="sha512.js"></script>
<script type="text/javascript" src="forms.js"></script>
<?php
include 'db_connect.php';
include 'functions.php';
sec_session_start();
if(isset($_GET['error'])) { 
  if($_GET['error']==1) {
    echo 'Error Logging In!';
  }
}
if(login_check($mysqli) == true) {
  header('Location: ./registration.php');
} else {
?>
<html>

<head>
   <title>Sprinkler Controller - Login</title>
</head>

<body>
    <table border="0" align="center">
    <form action="process_login.php" method="post" name="login_form">
       <tr>
       <td>Email:</td><td><input type="text" name="email"</td>
       </tr>
       <tr>
       <td>Password:</td><td><input type="password" name="password" id="password"/></td>
       </tr>
       <tr>
       <td colspan ="2" align="center"><input type="button" value="Login" onclick="formhash(this.form, this.form.password);" /></td>
       </tr>
    </form>
    </table>
</body>
</html>
<?php
}
?>

注意 login.php 从 forms.js 加载一个表单

function formhash(form, password) {
   // Create a new element input, this will be out hashed password field.
   var p = document.createElement("input");
   // Add the new element to our form.
   form.appendChild(p);
   p.name = "p";
   p.type = "hidden"
   p.value = hex_sha512(password.value);
   // Make sure the plaintext password doesn't get sent.
   password.value = "";
   // Finally submit the form.
   form.submit();
}

稍微阅读一下,我认为我需要添加一些东西来配合

$(document).on('submit', '#password', function(evt){
  evt.preventDefault();
})

但我不仅不确定我需要将它放在哪个文件和所述文件中的哪个位置,我不确定这是否是我真正需要做的来修复它!

4

2 回答 2

0

四处询问我发现总体问题是我试图将 login.php 文件中的整个 HTML 页面加载到 DIV 中。我放弃了 index.html 文件,直接进入 login.php,而不是尝试将其包装在 html 页面中。

于 2013-09-16T18:42:39.197 回答
0
<!doctype html>
<html>
<head>
</head>
<body>
<div id='myStyle'></div>
<script src="jquery.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $('#myStyle').load('./login.php');
    $(document).on('submit', 'form', function(evt){
      evt.preventDefault();
    })
  });
</script>
</body>
</html>
于 2013-09-13T18:31:49.023 回答