The Ajax of jquery

Source: Internet
Author: User

The Ajax part of jquery API

(1) JQuery object. Load (url,params,function (data) {}); (understanding)
(2) $.get (url,params,function (data) {},type); Ajax that sends a GET request
URL: The requested path
Params: The requested parameter parameter is in the form of Key\value key=value {"": "", "": ""}
Function: callback function parameter is the data sent back by the server
Type: Returns the content format, XML, HTML, script, JSON, text, _default. Use "JSON" later

(3) $.post (url,params,function (data) {},type); Ajax that sends a POST request
  
(4) $.ajax ([option]);
Optional values for the options:
URL: Request Path
Type: Request method
Data: Sent to the server
SUCCESS:FN the callback after successful
Callback after the ERROR:FN exception
DataType: Return content format often using JSON
Async: Setting Whether it is an asynchronous request
For example:

$.ajax ({                url:url,                type: "Post",                data:params,                success:function (d) {                    alert (d.msg);                },                error:function () {},                DataType: "JSON"                            }); 

If the result is in JSON format, the return value is printed as an object
For example, if the JSON is {"Result": "Success", "MSG": "Success"}
Get msg only requires parameters. msg

1. Front-end Ajax

Import JS:HTTP://PAN.BAIDU.COM/S/1JHLRVTK

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><script type= "Text/javascript" src= "${pagecontext.request.contextpath}/js/jquery-1.11.3.min.js" ></ Script><title>insert title Here</title><script type= "Text/javascript" >$ (function () {$ ("#btn"). Click (function () {var URL= "/day15/jqueryajax"; //var params= "Username= Zhang San";var params={"username": "Zhang Suna"}; //Load Mode            /*$ (this). Load (url,params,function (d) {alert (d); }); */                        //Get mode            /*$.get (url,params,function (d) {alert (d)});*/                        //Post Mode            /*$.post (url,params,function (d) {alert (d.msg); }, "JSON"); */                        //Ajax Way$.ajax ({url:url, type:"POST", Data:params, success:function (d) {alert (d.msg); }, Error:function () {}, DataType:"JSON"                            });            }); })</script>

2. servlet

 PackageCom.itheima.jquery_ajax;Importjava.io.IOException;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;/*** jquery's Ajax*/ Public classJqueryajaxservletextendsHttpServlet {Private Static Final LongSerialversionuid = 1L; protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {System.out.println ("Request method:" +Request.getmethod ()); //Accept ParametersString username = request.getparameter ("username"); Username=NewString (Username.getbytes ("iso-8859-1"), "Utf-8");                SYSTEM.OUT.PRINTLN (username); //Response DataResponse.getwriter (). Print ("Success"); }    protected voidDoPost (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {request.setcharacterencoding ("Utf-8"); System.out.println ("Request method:" +Request.getmethod ()); //Accept ParametersString username = request.getparameter ("username");        SYSTEM.OUT.PRINTLN (username); //response.getwriter (). Print ("Success"); //{"Result": "Success", "MSG": "Success"}String s= "{\" result\ ": \" Success\ ", \" msg\ ": \" success \ "}"; //Response DataResponse.setcontenttype ("Text/html;charset=utf-8");    Response.getwriter (). print (s); }}

3. Configure Web. xml

<servlet>    <description></description>    <display-name>jqueryajaxservlet</ display-name>    <servlet-name>JqueryAjaxServlet</servlet-name>    <servlet-class >com.itheima.jquery_ajax. jqueryajaxservlet</servlet-class>  </servlet>  <servlet-mapping>    < Servlet-name>jqueryajaxservlet</servlet-name>    <url-pattern>/jqueryAjax</url-pattern>  </servlet-mapping>

Problem

<script> is it before or after

jquery Selector

Reference: http://www.w3school.com.cn/jquery/jquery_intro.asp

Hierarchy Selector ★ All B        descendants of a b:a        a > b:a allb children        a+B:a's next brother (Big Brother)        a~b:a all the Younger brothers    Basic Filter Selector: ★        : Frist First        : Last        : Odd  index odd        : Even index even        : EQ (index) specify index         >        <     content filtering:        : Has ("selector"): element with the specified selector    visible filter:        : Hidden   In the page does not show element generally refers to input type= "hidden" and style in Display:none        : Visible     Property Filter: ★        [property name]        [property name] = "value"]    form filter:        : Input  All table list label  input Select TextArea button        //  Input

The Ajax of jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.