zoukankan      html  css  js  c++  java
  • 获取button自身id ajax发送后台 并接收返回数据并处理

    <script type="text/javascript">
        
                //$('.addpet').click(function () {
                //var form = new FormData(document.getElementById("formL"));
                $(document).ready(function(){
                    $('td > button').click(function(){
                        //alert($(this).attr("id"));
                        //alert($(this).html())
                    var content = $(this).attr("id");
                    if(content){
                // var content = $('.addpet').val();
                console.log(content);
                    
         // return;
                $.ajax({
                    url: "/admin/Contract/addpet",
                     type: "get",
                   
                     data: {'id':content},
                     dataType: "json",
     
                    success: function (res) {
                        console.log(res)
                        $(".vpets table thead").remove();
                        $(".vpets table tbody").remove();
                        var tempHtml = "<thead><tr><th>宠物名</th>"
                                        +"<th>品种</th><th>性别</th><th>绝育</th>"
                                        +"<th>生日</th><th>毛色</th><th>身高</th>"
                                        +"<th>体重</th></tr></thead>";
                        $.each(res.data,function(n,value){
                            tempHtml += "<tbody><tr><td>"+value.pet_name+"</td>"
                                        +"<td>"+value.pet_type+"</td>"
                                        +"<td>"+value.pet_sex+"</td>"
                                        +"<td>"+value.sterilization+"</td>"
                                        +"<td>"+value.birthday+"</td>"
                                        +"<td>"+value.color+"</td>"
                                        +"<td>"+value.height+"</td>"
                                        +"<td>"+value.weight+"</td>"
                                        +"<td><div class='actions'>"
                                        +"<a href='编辑产品分类.html' class='btn btn-sm bg-success-light mr-2'>"
                                        +"<i class='fe fe-pencil'></i>"
                                        +"<font style='vertical-align: inherit;'>"
                                        +"<font style='vertical-align: inherit;'>编辑"
                                        +"</font>"
                                        +"</font>"
                                        +"</a><a href='' class='btn btn-sm bg-danger-light'>"
                                        +"<i class='fe fe-trash'></i><font style='vertical-align: inherit;'>"
                                        +"<font style='vertical-align: inherit;'> 删除"
                                        +"</font></font></a></div></td><tr>"
                                        +"</tbody>";
                            //console.log(value.pet_name);
                        })
                        $(".vpets table").append(tempHtml);
                        
                        if (res.status == 0) {
                            alert(res.msg);
                            return;
                        }
                        //alert(res);
                        //location.href = res.url;
                        //return;
                        },
                    error:function(){
                        console.log("请求失败")
                        },
                        timeout:2000,
                    });
                    //success:function(res){
                        //console.log(res);
                        
                    //},
                    //error:function(){
                        //console.log("请求失败")
                        //},
                        //timeout:2000,
                    //});
                }
                })
                 })
            </script>
  • 相关阅读:
    HeadFirst学习笔记-1. 设计模式入门(转载)
    【译】StackExchange.Redis 中文文档目录(转载)
    Redis基础篇(一)数据类型与数据结构(转载)
    Redis基础(二)数据库(转载)
    Redis基础篇(八)数据分片(转载)
    Redis基础篇(七)哨兵机制(转载)
    Redis基础篇(六)数据同步:主从复制(转载)
    Python特点
    Python发展历史
    Python基础
  • 原文地址:https://www.cnblogs.com/wangyinqiuqian/p/12016287.html
Copyright © 2011-2022 走看看