springboot请求ajax

使用curl测试传入数组时的命令

curl -XPOST http://127.0.0.1:8080/HostManager/deleteHostInfoById -d'delete_pk=1,2,3'

后台代码

//返回的是List集合, 相当于数组

    @PostMapping("/listAll")
    @ResponseBody
    public List<Student> listAll(Model model){
        return studentRepository.findAll();
    }

前端

<script>
$(document).ready(function () {
    $("#but").click(function (){
        $.ajax({
            type: "POST",
            url: "/listAll",
            success:function (msg) {
                console.log(msg);
                console.log(msg[0]['name']);
                console.log(typeof msg);
                $.each(msg,function (index,value) {
                    console.log(index+"<=====>"+value['name']);
                })

            },
            error: function () {
                alert("请求超时");
            }
        });
    });
});
</script>

发布了27 篇原创文章 · 获赞 1 · 访问量 2618

猜你喜欢

转载自blog.csdn.net/bck1453925668/article/details/104911532