美文网首页
springboot发送ajax请求

springboot发送ajax请求

作者: rainbowz | 来源:发表于2019-08-27 22:53 被阅读0次
@Controller
@RequestMapping("api")
public class CityController {

    @Autowired
    private PeopleMapper peopleMapper;

    @GetMapping("index")
    public  String index(){
        return "city";
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST,value = "data")
    public List<People> data(Model model) {

        List<People> list =peopleMapper.findAll();


        list=peopleMapper.findAll();
        model.addAttribute("lists",list);
        return list;
    }

}
前端页面city.html
<div style="width: 1000px;" >
    <h3 align="center">第一个项目</h3>
    <table width="100%" border="1" cellspacing="1" cellpadding="0"  class="table table-striped">
        <tr>
            <td>id</td>
            <td>loginacct</td>
            <td>userpswd</td>
            <td>username</td>
            <td>email</td>
            <td>createtime</td>
        </tr>
        <tbody id="tbodydata">

        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        </tbody>

    </table>
</div>
<hr/>
<div>
    <button type="button" class="btn btn-primary" onclick="sendAjaxPeople()" >筛选</button>
</div>


<script >
    function sendAjaxPeople()
    {

        $.ajax(
            {
                url:"/api/data",
                data:{
                   /* "id":"id",
                    "loginacct":"loginacct",
                    "userpswd":"userpswd",
                    "username":"username",
                    "email":"email",
                    "createtime":"createtime"*/
                },
                type:"post",
                dataType:"json",
                success:function(data)
                {

                    optionJson=data;

                    var str="";

                    for(i in data){
                        str+="<tr>"+
                            "<td>"+data[i].id+"</td>"+
                            "<td>"+data[i].loginacct+"</td>"+
                            "<td>"+data[i].userpswd+"</td>"+
                            "<td>"+data[i].username+"</td>"+
                            "<td>"+data[i].email+"</td>"+
                            "<td>"+data[i].createtime+"</td>"+
                            "</tr>";
                    }

                    document.getElementById("tbodydata").innerHTML=str;

                   alert(JSON.stringify(data));
                },
                error: function() {
                    alert("error");
                }
            });
    }



</script>


页面


图片.png
图片.png
图片.png

参考:https://blog.csdn.net/oppo5630/article/details/52093898/
https://github.com/yaoql/SpringBootAjax

相关文章

  • springboot发送ajax请求

    页面 参考:https://blog.csdn.net/oppo5630/article/details/5209...

  • 用get、post方式发送ajax请求

    get方式发送ajax请求 post方式发送ajax请求

  • ajax

    特点 ajax ajax入门 ajax请求与发送数据 ajax工具类封装 type:请求类型url:请求地址dat...

  • 使用promise封装ajax请求

    封装一个ajax请求方法: 调用ajax方法,发送请求

  • JavaScript学习笔记(三十三)-- jQuery(下)

    jQuery 今天我们继续来聊 jQuery 发送 ajax 请求 发送 get 请求 发送 post 请求 综合...

  • jQuery+Ajax

    Ajax Ajax-HTTP请求 XMLHttpRequest发送请求 XMLHttpRequest取得响应 JS...

  • Ajax-03

    jQuery 中的 Ajax $.ajax()方法概述 作用:发送Ajax请求。 可替换属性 作用:发送jsonp...

  • ajax,本地存储

    ajax 发送http请求ajax技术的目的是让javascript发送http请求,与后台通信,获取数据和信息。...

  • 发送ajax请求

    发送ajax请求 vue本身不支持发送ajax请求,需要使用vue-resourc axios等插件实现,建议使用...

  • 六、Vue.js

    一、发送AJAX请求 1.简介 2,使用axios发送ajax请求 2.1安装axios并引入 2.1基本用法 3...

网友评论

      本文标题:springboot发送ajax请求

      本文链接:https://www.haomeiwen.com/subject/ptfuectx.html