Santosh Jadi Santosh Jadi - 7 months ago 8
HTML Question

Set json values to HTMLTable in Java Script?

function loadUserTable(userType){
$.ajax({
type: "POST",
url: "loadUserTable.html",
data: "userType=" + userType,
success: function(response){

alert(response);

},
});
}


Im still working on it,
I print alert for output and got as below

[{
"userId":1,
"email":"santosh.jadi95@gmail.com",
"mobile":"9900082195",
"gender":"male",
"qualification":"1",
"dob":"2016-01-01",

"login":{
"loginId":1,
"userName":"santosh",
"password":"santosh",
"userType":"admin"
}
}]


I want the above json values in an HTML Table, is it Possible?
If yes, then i just want to know that, how it can be done?

Answer

Got the Solution,, Thank u all for the kind support

 function loadUserTable(userType){
              $.ajax({
                    type: "POST",
                    url: "loadUserTable.html",
                    data: "userType=" + userType,
                    success: function(response){
                        var obj = JSON.parse(response);
                        $("#tableId").html("");
                        var tr+="<tr><th>User ID</th><th>User Name</th></tr>";
                        for (var i = 0; i < obj.length; i++){
                              tr+="<tr>";
                              tr+="<td>" + obj[i].userId + "</td>";
                              tr+="<td>" + obj[i].login.userName + "</td>";
                              tr+="</tr>";
                        }
                        $("#tableId").append(tr);
                    }
              });
      }
Comments