我有 2 页
- 索引.php
- 登录.php
从 index.php 进行 ajax 调用并获取 login.php
索引.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home Page</title>
<script src="./js/jquery.js"></script>
<script>
$(document).ready(function(e) {
$("a").click(function(e) {
var model= $.ajax({
url: $(this).attr('href'),
cache:false,
type: "GET",
dataType:"json"
});
model.done(function(data){
$("#body").html(data.bodyy);
e.preventDefault();
});
});
$("form").submit(function(e) {
alert("Triggered");
});
});
</script>
<body>
<div id="body"><a href="login.php">Login</a>
</div>
</body>
</html>
这是ajax页面:login.php
<?php
$body='<form class="form-signin" action="#" method="post" id="login">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="input-block-level" placeholder="username" name="username">
<input type="password" id="password" class="input-block-level" placeholder="Password" name="password">
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
</label>
<table><th>
<button class="btn btn-large btn-primary" type="submit">Sign in</button> </th><th width="5%">
<h3> or </h3></th><th>
<a class="btn btn-large btn-primary" href="./registration.php" >Register</a></th></table>
</form>
<script>
</script>
';
$data= array(
'bodyy' => $body,
);
echo json_encode($data);
?>
当我提交登录表单时,$("form").submit(function(e)
未调用。当我从 ajax 加载页面调用它时,我遇到了这个问题