使用load()方法异步请求数据

使用 load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为:

load(url,[data],[callback])

参数url为加载服务器地址,可选项data参数为请求时发送的数据,callback参数为数据请求成功后,执行的回调函数。

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3     <head>
 4         <title>使用load()方法异步请求数据</title>
 5         <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
 6         <link href="style.css" rel="stylesheet" type="text/css" />
 7     </head>
 8     
 9     <body>
10         <div id="divtest">
11             <div class="title">
12                 <span class="fl">我最爱吃的水果</span> 
13                 <span class="fr">
14                     <input id="btnShow" type="button" value="加载" />
15                 </span>
16             </div>
17             <ul></ul>
18         </div>
19         
20         <script type="text/javascript">
21             $(function () {
22                 $("#btnShow").bind("click", function () {
23                     var $this = $(this);
24                     $("ul").load("./fruit.html",function(){
25                         $this.attr("disabled", "true");
26                     });
27                 })
28             });
29         </script>
30     </body>
31 </html>
View Code
1 <ul>
2     <li>橘子</li>
3     <li>香蕉</li>
4     <li>葡萄</li>
5     <li>苹果</li>
6 </ul>
View Code

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值