JQuery AJAX $.post () method

Source: Internet
Author: User
Tags http post

AJAX = asynchronous JavaScript and XML.
AJAX is a technique for creating fast, Dynamic Web pages.
AJAX allows Web pages to be updated asynchronously by exchanging small amounts of data in the background with the server. This means that it is possible to update part of a Web page without overloading the entire page.
There are many methods of Ajax submissions provided in the jquery scripting library, but the main methods are $.get (), $.post (), $.ajax (). where $.ajax () is the underlying implementation of the first two methods and can provide more properties and parameter settings than the previous one, it is recommended to use the $.ajax () method if advanced settings are required.
"Reproduced use, please specify the source:http://blog.csdn.net/mahoking"

Learn $.get () method
Learn $.post () method
Learn $.ajax () method

The

$.post () Method
Post () method loads data from the server over an HTTP POST request.
Syntax:
$.post (url,data,success (data, Textstatus, JQXHR), DataType)
Comment:
url                                     required. Specifies which URL to send the request to. The
data           is optional. The map or string value. Specifies the data that is sent to the server along with the request.
Success (data, Textstatus, JQXHR)     Optional. The callback function to execute when the request succeeds.
datatype                        Optional. Specifies the data type of the expected server response. The
performs smart judgments by default (XML, JSON, script, text, HTML, and so on).

demo case:
1,   Create Web project Jqueryajax.
2,   create js/jquery file directory under Webroot, add Jquery-2.1.1.js
3,   create servlet (Ajaxpostservlet). As follows:

public class Ajaxpostservlet extends HttpServlet {public void doget (HttpServletRequest request, HttpServletResponse Response) throws Servletexception, IOException {retdata (Request, Response, "GET");} public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { Retdata (Request, Response, "POST");} /** * Provide return data to request * @param request * @param response * @param method * @throws ioexception */private void Retdata (Httpservle Trequest request, HttpServletResponse Response,string method) throws ioexception{string UserName = Request.getparameter ("UserName"); String age = Request.getparameter ("Age"); PrintWriter out = Response.getwriter (); Out.print (method+ ": Username=" +username+ ", age=" +age); Out.flush ();}}

4, create jquery_ajax_method_post.jsp.

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%string path = Request.getcontextpath () ; String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE html>

5. Deploy the project to Tomcat and test it.


"Reproduced use, please specify the source: http://blog.csdn.net/mahoking "



JQuery AJAX $.post () method

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.