jQuery Ajax 方法应用。

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>

 

posted @ 2014-09-18 14:36  宇宙第一小菜鸟  阅读(114)  评论(0编辑  收藏  举报