<body> <input type="button" value="Ajax" /> <div id="box"></div> </body>
服务器html文件:
<span class="name">党兴明</span> <span class="age">24</span>
php:
<?php if($_POST['age'] == 24){ echo 'php:党兴明24'; }else{ echo '木有'; } ?>
js:
$(function(){ $('input').click(function(){ $('#box').load('test.html .age'); }); $('input').click(function(){ $('#box').load('test.php?age=2'); }); $('input').click(function(){ $('#box').load('test.php',{ age:24 },function(response,status,xhr){ alert(response); $('#box').html(response+',哈哈'); alert(status); alert(xhr.responseText); alert(xhr.responseXML); alert(xhr.status); alert(xhr.statusText); }); }); });
注:load()适合获取服务器端的静态文件,局部方法