前后数据交互(ajax) -- 初始化页面表格

// 初始化员工信息列表
function loadpage ( pageNum ) {
    var keywords = $("#keywords").val();
    $("#tbody").html("");

    if ( isNaN(pageNum) ) {
        pageNum = 1;
    }

    $.$.ajax({
        type: 'GET',
        url: contextPath + "/getaccountList/" + pageNum + "/" + pageSize,
        dataType: 'json',
        contentType: "application/json;charset='UTF-8'",
        data: {
            keywords: keywords 
        },
        cache: false
        success: function () {
            if( data.code == 0 ){
                // 系统异常
                
            } else if (data.code == 1) {
                // 成功
                if ( data.data.size != 0 ) {
                    $("#tbody").html('');
                    $.each(data.data.list, function () {
                        $tr = $("<tr/>");
                        $td1 = $("<td/>").text(item.number == null ? "" : item.number);
                        $td2 = $("<td/>").text(item.nickName == null ? "" : item.nickName);
                        $td3 = $("<td/>").text(item.tel == null ? "" : item.tel);
                        $td4 = $("<td/>").text(item.createTime == null ? "" : item.createTime);
                        $td5 = $("<td/>").text(accountRole(item.roleId));
                        $td6 = $("<td/>").text(item.status == 0 ? "正常" : "停用");
                        $td7 = $("<td/>")
                        $tdai2 = $("<i/>").addClass('iconfont icon-btn reset-pwd').attr({
                            "title": "重置密码",
                            "data-id": item-userId
                        }).html("�");
                        $td7.append(choiceStatus(item.userId, item.status, item.nickName)).append($tdai2);
                        $tr.append($td1).append($td2).append($td3).append($td4).append($td5).append($td6).append($td7);              

              //$tr.append($td1);
              //$tr.append($td2);
              //$tr.append($td3);
              //$tr.append($td4);
              //$tr.append($td5);
              //$tr.append($td6);
              //$tr.append($td7);

                        // 追加到tbody中
                        $("#tbody").append($tr);

                    });

                    // 初始化功能事件
                    initEvent(2);

                } else {
                    // 数据为空
                }
                // 分页加载
                createPageText(data.data);
            
            } else if (data.code == -1) {
                // 未登录
                index();
            } 

        } // success end
    }) // ajax end 

}
 

  

原文地址:https://www.cnblogs.com/zsongs/p/5998230.html