1. Jquery.post(URL, [data], [callback], [type]): Use post to make asynchronous requests
1.1 ParametersURL(String): The URL address of the sending request.Data(MAP): (optional) data to be sent to the server, expressed as a Key/value key-value pair.Callback(function): (optional) The callback function when loading succeeds (the method is called only if the return state of response is success).type(String): (optional) The official description is: Type of data to be sent. The type that should actually be requested for the client (Json,xml, etc.)1.2 jquery Ajax interacts with Java via post1.2.1 HTML code
<body><div id= "main" ><button id= "mybut" >ajax get Data </button><div id= "container" ></ Div></div></body>
1.2.2 Style Code
<style type= "Text/css" > #main {margin:0 auto;width:400px;} #container {width:400px;height:300px;border:1px dashed #666; text-align:center;line-height:300px;} </style>
1.2.3 Javsscript Code
<script type= "Text/javascript" src= "js/jquery-1.8.3.js" ></script><script type= "Text/javascript" >$ (function () {$ (' #myBut '). Click (function () {$.post ("Jqueryajaxservlet", {age:18,name: "Zhang"}, function (data, Textstatus) {var container = $ (' #container '); var resultdata = $.parsejson (data); var = resultdata.age;var name = result Data.name;container.html ("Name:" + name + "," + "Age:" + Age);});}); </script>
1.2.4 Jqueryajaxservlet.java Code
public class Jqueryajaxservlet extends HttpServlet {public void doget (HttpServletRequest request, HttpServletResponse Response) throws Servletexception, IOException {String age = request.getparameter ("Age"); String name = Request.getparameter ("name"); String Personjson = "{\" name "+" \ ": \" "+ name +" \ "," + "\" age "+" \ ":" + Age + "}"; System.out.println (Personjson); Response.getwriter (). write (Personjson);} public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { Doget (request, Response);}}
1.2.5 Web. XML Code
<servlet> <servlet-name>JqueryAjaxServlet</servlet-name> <servlet-class> com.jquery.ajax.com.jqueryajaxservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>JqueryAjaxServlet</servlet-name> <url-pattern>/jqueryajaxservlet</ url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp </welcome-file> </welcome-file-list>
6, jquery Ajax and Java through the post mode interaction