Jquery Ajax

阅读更多
1. Jquery Ajax简介

Jquery对Ajax操作封装了一套跨浏览器,方便用户使用的Api


2. Jquery Ajax Load方法

远程请求,把请求的数据载入到DOM里;
load(url , [,data] , [,callback])
Url:请求地址
Data:请求参数
Callback:请求完成后的回调方法


3. jquery Ajax Get/Post方法

Ajax请求后台;
$.post(URL,data,callback);
Url:请求地址
Data:请求参数
Callback:请求完成后的回调方法


chap06/demo01.html





Insert title here







姓名:
年龄: Web.xml HeadFirstJquery index.html ajaxServlet com.andrew.web.AjaxServlet ajaxServlet /ajax AjaxServlet.java package com.andrew.web; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class AjaxServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String action = request.getParameter("action"); if ("load".equals(action)) { this.load(request, response); } else if ("post".equals(action)) { this.post(request, response); } } private void load(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); String name = request.getParameter("name"); String age = request.getParameter("age"); System.out.println("name:" + name); System.out.println("age:" + age); PrintWriter out = response.getWriter(); out.println("jquery Ajax 大爷你好"); out.flush(); out.close(); } private void post(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); String id = request.getParameter("id"); System.out.println("id:" + id); PrintWriter out = response.getWriter(); out.println("{name:'张三',age:14}"); out.flush(); out.close(); } } http://localhost:8080/HeadFirstJquery/chap06/demo01.html

你可能感兴趣的:(jquery)