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>
  • 相关阅读:
    css整理-06 表和列表
    css整理-05 边框,背景和浮动,定位
    css整理-04 基本视觉格式化
    css整理-03 文本
    css整理-02 颜色和字体
    no-jquery 05 Utilities
    no-jquery 04 Events
    使用nodejs写个服务器小程序
    快速判断数组中每个对象同一属性值是否相同
    飞快验证对象是否为空
  • 原文地址:https://www.cnblogs.com/wangyinqiuqian/p/12016287.html
Copyright © 2011-2022 走看看