我尽力复制文件,让用户在信息输入用户和密码文本框时看到显示的信息。但是,信息显示没有发生。
以下是我的ajax. html文件:
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
var sendu = $("#username").val();
var sendp = $("#pw").val();
$.ajax({
type: "POST",
url: "ajax.php",
data: "username="+sendu+"&password="+sendp,
dataType: "json",
success: function(msg, string, jqXHR){
$("#result").html(msg+string+jqXHR);
}
});
});
});
</script>
</head>
<body>
<input type="text" id="username" name="username" /><br />
<input type="password" id="pw" name="pw" /><p>
<input type="button" id="button" value="Submit" />
<p><div id="result"></div>
</body>
</html>
这是我的ajax.php文件:
<?php
$name = $_REQUEST["username"];
$pw = $_REQUEST["pw"];
$list = array( name =>$name, password =>$pw);
$c = json_encode($list);
echo $c;
?>