JQUery_review: jQuery's ultimate ajax method $. ajax ()
There have been many projects, large and small, and many of the lower-layer encapsulation methods of the frameworks are expanded on the basis of the ajax () method. The ajax method is the first of all ajax-related methods provided by jQuery. All other methods, such as load, get, post, getScript, and getJson, are extended to the jQuery. ajax method.
The following is an actual DEMO that uses the above parameters:
Code of the front-end page:
<%@ 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.
Backend code:
@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());}
In fact, the best information about jQuery is the official document, which contains all the details and has a good weekend!