jQuery Ajax 方法應用。

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   for   資料   div   

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 json10                     contentType:‘application/x-www-form-urlencoded;charset=utf-8‘, //encoded11                     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 方法應用。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.