关于AJAX的问题,总是报未找到元素

浏览:1620 发布日期:2016/05/09 分类:求助交流 关键字: ajax,thinkphp,jq,js
[b color="red"]这是HTML代码:[/b]<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";
?>
最佳答案
评论() 相关
后面还有条评论,点击查看>>