<body> <div class="container"> <h2>ajax 操作实例</h2> <p>姓名:</p> <input type="text" id="name" /><br/
<body>
<div class="container">
<h2>ajax 操作实例</h2>
<p>姓名:</p>
<input type="text" id="name" /><br/>
<p>年龄:</p>
<input type="text" id="age" /><br/><br/>
<input type="submit" id="sub" />
</div>
</body>
</html>
<script type="text/javascript">
alert(22);
$('#sub').click(function(){
var name = $('#name').val();
var age = $('#age').val();
$.ajax({
url:'__ACTION__',
data:{
name:'name',
age :'age',
},
type:'get',
// dataType:'json',
success:function(msg){
if(msg==1){
alert(33);
clearInterval();
}
},
error:function(msg){
alert('error');
}
})
})
</script>
后台
public function ajax(){
if(IS_AJAX){
$this->ajaxReturn(1,'json');
}
$this->display();
}