第12章 Ajax(上)

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);
		});
	});	
	
});

猜你喜欢

转载自onestopweb.iteye.com/blog/2226303