<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>使用ajax()方法加载服务器数据</title>
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<style type="text/css">
.title{
width: 300px;
height: 50px;
line-height: 50px;
color: #fff;
font-weight: bold;
background-color: green;
}
.fl{
float: left;
}
.fr{
float: right;
}
ul li{ list-style-type: none;}
</style>
</head>
<body>
<div id="divtest">
<div class="title">
<span class="fl">加载一段文字</span>
<span class="fr">
<input id="btnShow_1" type="button" value="加载1"/>
<input id="btnShow_2" type="button" value="加载2"/>
</span>
</div>
<ul></ul>
</div>
<script type="text/javascript">
$(function(){
$.ajaxSetup({
dataType: 'text',
success:function(data){
$("ul").empty().append(data);
}
});
$('#btnShow_1').bind('click',function(){
$.ajax({
url:'data/article_1.txt'
});
});
$('#btnShow_2').bind('click',function(){
$.ajax({
url:'data/article_2.txt'
});
});
});
</script>
</body>
</html>