Encapsulation of Ajax function in jQuery

$.ajax({
    type : "post",
    url : "workbench/customer/selectAll.do",
    success : function(data){
        if(data.success){
            var html = "";
            $.each( data.customerList, function(i , n){                       
                html += "<tr>";
                html += "<td><input type="checkbox" value=""+n.id+""/></td>";
                html += "<td><a style="text-decoration: none; cursor: pointer;" onclick="window.location.href="workbench/customer/detail.jsp">"+n.name+"</a></td>";
                html += "<td>"+n.owner+"</td>";
                html += "<td>"+n.phone+"</td>";
                html += "<td>"+n.website+"</td>";
                html += "</tr>";
            })                    
            $("-sharpcustomerTbody").append(html);
        }else{
            alert("");
        }
    }
})
,?
Mar.13,2021

just throw it into the function and call it, don't you?

function name(){
    $.ajax({
    type : "post",
    url : "workbench/customer/selectAll.do",
    success : function(data){
        if(data.success){
            var html = "";
            $.each( data.customerList, function(i , n){                       
                html += '<tr>';
                html += '<td><input type="checkbox" value="'+n.id+'"/></td>';
                html += '<td><a style="text-decoration: none; cursor: pointer;" onclick="window.location.href="workbench/customer/detail.jsp">'+n.name+'</a></td>';
                html += '<td>'+n.owner+'</td>';
                html += '<td>'+n.phone+'</td>';
                html += '<td>'+n.website+'</td>';
                html += '</tr>';
            })                    
            $("-sharpcustomerTbody").append(html);
        }else{
            alert("");
        }
    }
})    
};
name();

of course. What do you think is the reason why not?


encapsulate a method:
function ajaxFunc (type, url, customerTbody, eachContent) {

$.ajax({
type : type,
url : url,
success : function(data){
    if(data.success){
        var html = "";
        $.each( data.customerList, function(i , n){                       
           var html = eachContent;
        })                    
        $(customerTbody).append(html);
    }else{
        alert("");
    }
}
})

}

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35b7f-34382.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35b7f-34382.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?