Home > Web Front-end > JS Tutorial > Example analysis of get() and post() in ajax application in jquery

Example analysis of get() and post() in ajax application in jquery

黄舟
Release: 2017-09-07 14:11:00
Original
1409 people have browsed it

ajax application in jquery - get() and post()

get and post send data in different ways, but in jquery's ajax this difference is not visible to the user. There is a limit to the size of data transmitted by get. The data requested by get will be cached by the browser. The two methods are received differently on the server side.

get()
The get function form in jquery is $.get(URL,data,callback,type);

The code is as follows:

$.get("web.jsp",{
    name:"name1",                                            //get方法中的数据不仅可以是映射方法,也可以是"name=name1&age=12"的字符串方式,
    age:"12"                                                  //如果有中文,要使用编码,"name="+encodeURIComponent("栾鹏")+"&age=12"},
    function(data,textStatue){                                  //data表示返回的内容,可以是xml,JSON文件,HTML片段。textStatus表示请求状态:sucess,error,notmodified,timeout4种
    $("#p1").html(data);                                    //如果是html片段,直接设置代码段
    username = $(data).find("comment").attr("username");      //如果是xml文档,则使用$转化为dom对象
    username = data.username;                                 //如果是json数据,当成对象使用});
Copy after login

post()
The post function form in jquery is $.post(URL,data,callback);
The code is as follows:

$.post("web.jsp", $("#form1").serialize(),                 //serialize序列化表单内容,作为jQuery的表单对象的函数。
    function(data,textStatue){                              //data表示返回的内容,可以是xml,JSON文件,HTML片段。textStatus表示请求状态:sucess,error,notmodified,timeout4种
    $("#p1").html(data);                                    //如果是html片段,直接设置代码段
    username = $(data).find("comment").attr("username");      //如果是xml文档,则使用$转化为dom对象
    username = data.username;                                 //如果是json数据,当成对象使用});
Copy after login

The above is the detailed content of Example analysis of get() and post() in ajax application in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template