首页 > Web开发 > 详细

jQuery Ajax 方法应用。

时间:2014-09-18 16:09:44      阅读:326      评论:0      收藏:0      [点我收藏+]

jquery中的ajax方法比原生js简洁多了,写了一个小例子。

贴码:

 1  <script>
 2     $(function(){
 3         
 4         $(‘#getData‘).click(function(){
 5                     
 6                 $.ajax({
 7                     type:‘post‘, //get or post
 8                     url:‘test.txt‘, //request url
 9                     dataType:‘text‘,// response dataType  Text or json
10                     contentType:‘application/x-www-form-urlencoded;charset=utf-8‘, //encoded
11                     success:function(data){  //成功调用的回调函数 data是获取到的数据
12                         //console.log(data);  
13                         $(‘.c‘).html(data);  //可以对函数进行一系列的操作
14                     }

              error:function(){...} //失败调用的函数
15 }); 16 17 }) 18 19 }) 20 </script> 21 </head> 22 23 <body> 24 25 <button id=‘getData‘ >Get Data By Ajax</button> 26 <div class=‘c‘> 27 28 </div> 29 </body>

 

jQuery Ajax 方法应用。

原文:http://www.cnblogs.com/hellome/p/3979196.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!