从后台获取数据

137 阅读1分钟

首先打开后台运行nodejs 然后

\

   

   

   

    标签管理

   

   

   

   

        .alert {

            margin: 5px 10px;

        }

   

\

   

\

   

\

   

       

            TAG标签管理

           


       

       

           

               

                   

\

               

               

                   

\

               

           

       

       

           

\

           

       

   

\

   

   

   

        $(function () {

            load();

\

            $("form").submit(function () {

                $.ajax({

                    url: "http://localhost:3009/tag",

                    type: "POST",

                    data: { text: $("#text").val() },

                    success: function (res) {

                        if (res.status === 200) {

                            load();

\

                            console.log("添加成功");

                        }

                    }

                })

                return false;

            })

            $(".col-xs-12").on("click", ".close", function () {

                var id = $(this).attr("data-id");

                $.ajax({

                    url: "http://localhost:3009/tag",

                    type: "DELDETE",//请求方法

                    data: { _id: id },

                    success: function (res) {

                        if (res.status == 200) {

                            console.log("删除成功");

                        }

                    }

                })

            })

            function load() {


\

                $.ajax({

                    url: "http://localhost:3009/tag",

                    type: "GET",//请求方法

                    success: function (res) {

                        if (res.status === 200) {

                            const data = res.data;

                            //    声明变量

                            let html = "";

                            for (let index = 0; index < data.length; index++) {

                                const element = data[index];

                                html += `

                                     ×

                                      ${element.text}

                                     

                                   

`;

                                $(".col-xs-12").html(html);//element.text

                            }

                        }

                        console.log(res);

\

                    },

                    error: function (err) {

                        console.log(err);

                    }

                })

            }

        })