当前位置: 移动技术网 > IT编程>开发语言>Java > 使用Ajax简单获取数据

使用Ajax简单获取数据

2020年07月14日  | 移动技术网IT编程  | 我要评论

使用注解@ResponseBody //将方法返回值直接响应给客户端(使用Fastjson)

注意在SpringMvc配置文件中配置Fastjson消息转换器

举例:

前端页面中使用Ajax获取数据并且在前端页面中通过使用table展示用户列表数据

 $.ajax({

            url:"/ssm_02_code/getUserList.do",

            dataType:"json",

            success:function (result) {

                if(result.code==100){

                    //渲染数据

                    renderData_user(result.data);

                }else {

                    $("#info").text("页面访问出错");

                    $("#table_user").remove();

                }

            }

        });

        function renderData_user(data) {

            var template_tr=$("#table_user tr:eq(1)");

            $("#table_user tr:eq(1)").remove();

            for(var i in data){

                var tr =template_tr.clone();

                tr.find("#userCode").text(data[i].userCode);

                tr.find("#userName").text(data[i].userName);

                tr.find("#gender").text(data[i].gender==1?"女":"男");

                tr.find("#age").text(data[i].age);

                tr.find("#phone").text(data[i].phone);

                $("#table_user").append(tr);

            }

        }

本文地址:https://blog.csdn.net/ClearLex/article/details/107290997

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网