$.ajax({ url: "<?php echo Router::url(array('controller'=>'home','action'=>'checkAssignList'));?>", type: 'POST', data: { userid : userid }, success: function(data){ if (data == '0') { string += "<tr><td colspan=\"2\" ><center> No data </center> </td></tr>"; } else { catlist = $.parseJSON(data); $.each(catlist, function(index, val) { string+="<tr id='row"+val.Category.id+"'>"; string+="<td>"+val.Category.name+"</td> "; string+="<td><button onclick=\"unAssign('"+val.Category.id+"', '"+ userid+"')\" class='btn btn-small btn_unAssignt12'>unAssign</button></td> "; string+="</tr>"; }); } $('#categoriesDatalist').html(string); }//end success ! })//end ajax function loadalllistUsersAssign