Home  >  Article  >  Web Front-end  >  Example of post method usage in jquery_jquery

Example of post method usage in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 16:33:081325browse

The example in this article describes the usage of the post method in jquery and is shared with everyone for your reference. The specific usage analysis is as follows:

When using jquery to implement asynchronous interaction on the website, the two commonly used functions are the get and post methods. The get method is very simple to use. Just submit the get request directly. If there are parameters, just append them to the url. But use When passing the parameter in the post method, it needs to be written separately from the URL, which makes passing the parameter cumbersome. However, it is safer to do so, and the probability of Chinese garbled characters is also lower (the get method often passes Chinese characters with garbled characters). Phenomenon), here is a detailed introduction to how posts pass parameters.

First write an html code as follows:

Copy code The code is as follows:


jquery post method test










The post method code in the server-side servlet is as follows (the servlet class name is login, and its access path is configured as servlet/login)
Copy code The code is as follows:
response.setContentType("text/html");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gb18030");
String name= request.getParameter("name");
String pass= request.getParameter("pass");
out.print("name:" name "pass:" pass);
out.flush();
out.close();

After running the above HTML code on the client, click the "Test" button, and the name: entered user name pass: entered password dialog box will pop up. By analyzing the HTML code, we can know that the post method uses the data json format to pass parameters. .

Supplement:

In the case of garbled Chinese characters, The default Chinese character encoding of ajax is utf-8, and the encoding of the post receiving page should also remain the same coding.

I hope this article will be helpful to everyone’s Ajax programming based on jQuery.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn