ajax中
(1)
<div id="form">
账号:<input type="text" name="" value=""><br>
密码:<input type="text" name="" value=""><br>
<button id="btn">登录</button>
</div>
<script type="text/javascript" src="ajax.js"></script>
<script>
var form=document.getElementById('form');
var btn=document.getElementById('btn');
var user=form.getElementsByTagName('input')[0];
var pass=form.getElementsByTagName('input')[1];
btn.onclick=function (){
ajax('form.php?user='+user.value+'&pass='+pass.value,function (str){
alert(str);
});
}
</script>
(2)
<form method="get" action="form.php">
账号:<input type="text" name="user" value=""><br>
密码:<input type="text" name="pass" value=""><br>
<input type="submit" name="" value="登录">
</form>
在JQajax中
<form>
用户名:<input type="text" value="" name="user">
密码:<input type="password" value="" name="pass">
<input id="btn" type="submit" value="提交">
</form>
<script src="jquery-1.8.3.min.js"></script>
<script>
$('#btn').click(function(){
$.ajax({
type:'get',
url:'act.php',
data:$('form').serialize(),
dataType:'json',
success:function(data){
alert(data.msg);
},
error:function(e){
alert(e);
}
});
});
</script>