jquery+ajax+php的简单实现

test.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>测试</title>
<script type="text/javascript" src="../../jquery-1.3.2/jquery-1.3.2.js"></script>
<script type="text/javascript">
<!--
$(document).ready( function () {
	$('#repet').click(copycontent);						 
							 
	$('#btn').click ( function () {
		$.ajax({
		url: 'test.php?action=step',
		type: 'POST',
		data:'num='+$('#vcolum').val(),
		dataType: 'html',
		timeout: 1000,
		error: function(){
		 alert('Error loading XML document');
		},
		success: function(html){
		 $('#text').html(html);
		}
		});
	});
})

function copycontent(){
	var repetnn;
	repetnn = $('#hfcon').html();
	repetnn = '<blockquote class="b"><p>'+repetnn+'</p></blockquote>';
	$('#hfcon2').html(repetnn);
	//$('#content').val(repetnn);
}
//-->
</script>
<style>
.b{
border:1px dotted #e3e3e3;
background:#f6f6f6;
}
</style>
</head>

<body>
<div id="hfcon">
<blockquote class="b"><p>
	comment (1)</p>

<blockquote class="b"><p>
		comment (1.1)
	</p></blockquote>
<blockquote class="b"><p>
		comment (1.2)</p>
<blockquote class="b"><p>
			comment (1.2.1)
			<blockquote class="b"><p>
			comment (1.2.1.1)
		</p></blockquote>
		</p></blockquote>
</blockquote>
</blockquote>
<div id="repet"><a href="#">回复</a></div>
<p></p>
</div>
<div id="hfcon2">

</div>
<input type="text" id="vcolum" name="vcolum" />
<input type="button" value="查看" id="btn"/>
<div id="text"></div>
<p></p>
<textarea name="content" cols="80" rows="10" id="content"></textarea>
</body>
</html>


test.php
<?
include_once('common.inc.php');
include_once(CORE.'user.class.php');

$user = new user();

$num = trim($_POST['num']);
$action = $_REQUEST['action'];
$list = $user->getall($num);

foreach($list as $value1){
	foreach($value1 as $value2 ){
		echo $value2.'<br>';
	}
}

echo $action;
//echo '<pre>';

?>

你可能感兴趣的:(html,jquery,Ajax,PHP,XHTML)