jQUery_review之jQuery的終極ajax方法$.ajax()

來源:互聯網
上載者:User

jQUery_review之jQuery的終極ajax方法$.ajax()
經過的項目大大小小也有非常多的了,印象中很多架構低層封裝的方法都是在ajax()方法的基礎上進行擴充的。ajax方法可以說是jQuery提供的各式各樣的ajax相關方法的鼻祖,所有其他的比如load,get,post,getScript,getJson方法都是擴充於jQuery.ajax方法。
下面是一個實際的DEMO,將上面的參數都用了一遍:

前端頁面的代碼:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>    <script type="text/javascript" src="jquery-1.8.3.js"></script><script type="text/javascript">$(function(){$("#getContent").click(function(){$.ajax({url:"test",type:"get",timeout:2000,data:{name:"czz",address:"address"},dataType:'html',beforeSend:function(){alert('beforeSend');},complete:function(){alert('complete');},success:function(data,status){alert(data);},error:function(){alert('error');},global:false});});});  </script>      He who hesitates is lost.    

後端的代碼:

@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {String name = req.getParameter("name");String address = req.getParameter("address");StringBuffer sb = new StringBuffer("");sb.append("{\"name\":\"")  .append(name)  .append("_czz\",\"address\":\"")  .append(address)  .append("_czz\"}");resp.getWriter().print(sb.toString());}

其實jQuery最好的資料就是官方的文檔,上面有所有詳細的內容,周末愉快!


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.