<html>
<meta charset="utf-8"/>
<head>
<title>jQuery Ajax 实例演示</title>
</head>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#subbtn").click(function() {
var name = $('#username').val();
var password=$('#password').val();
var url = "demo.php";
data={username:username,password:password};
$.ajax({
type: "post",
url: url,
//dataType: "json",
data: "data",
success: function(a){
alert('a');
var tishi = "您提交的姓名为:" + a.username +
"<br /> 您提交的密码为:" + a.password;
$("#tishi").html(tishi);
$("#tishi").css({color: "green"});
}
});
});
});
</script>
<p><label for="name">姓名:</label>
<input id="username" name="username" type="text" />
</p>
<p><label for="password">密码:</label>
<input id="password" name="password" type="password" />
</p>
<span id="tishi"></span>
<p><input id="subbtn" type="button" value="ajax 测试" /></p>
</body>
</html>[b color="red"]这是php代码:[/b] <?php
$a['username']=$_POST['username'];
$a['password']=$_POST['password'];
//cho json_encode($a);
echo "$a";
?> 最佳答案