index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <Meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ajax</title> <script type="text/javascript" src="jquery-1.10.1.js"></script> <script type="text/javascript" src="demo.js"></script> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <body> <input type="button" value="异步加载数据" /> <div id="Box"></div> </body> </html>
test.html
<span class="title">一站式建网站</span> <span class="url">onestopweb.cn</span>
test.PHP
<?PHP //echo '一站式建网站'; /* if($_GET['url'] == 'onestopweb'){ echo '一站式建网站'; }else{ echo '不存在'; } if($_POST['url'] == 'onestopweb'){ echo '一站式建网站'; }else{ echo '不存在'; } */ if($_POST['url'] == 'onestopweb'){ echo '一站式建网站'; }else{ echo '不存在'; } ?>
demo.js
$(function(){ /* $('input').click(function(){ $('#Box').load('test.html .url'); }); $('input').click(function(){ $('#Box').load('test.PHP'); }); $('input').click(function(){ $('#Box').load('test.PHP?url=onestopweb'); }); */ $('input').click(function(){ $('#Box').load('test.PHP',{ url : 'onestopweb' },function(response,status,xhr){ //alert(response); //$('#Box').html(response+'123'); //alert(status);//打印 success //if(status == 'success'){alert('成功后的处理')}; //alert(xhr.responseText); //alert(xhr.responseXML); //alert(xhr.status); alert(xhr.statusText); }); }); });