-1

need your help.I want to write some JSTL code like <C:IF> in ajax but it doest not work

function myfunction(cd){

$("#datatable tbody").empty();
$.ajax({
    url :'/KurirCC/management-user-by-request.html',
    cache :true,
    data :{"kode":cd},
    dataType :"json",
    type : "GET",
    contentType : "application/json; charset=utf-8",
    success : function(jsondata){

        $.each(jsondata.data,function(i,obj){
            var status = obj.sts;
            tableHtml ="<tr> <td>"+ obj.id_mobile + "</td> <td>" + obj.nama +"</td> <td>"+ obj.username +"</td> <td>"
            + obj.kota + "</td> <td><c:if test="${status == 1}">Aktiv</c:if></td><td align='center'><button type='button' class='btn tom-history' title='History' ></button></td> </tr>";
            $(tableHtml).appendTo('#datatable tbody');
        }); 
    }

});

}

this code <td><c:if test="${status == 1}">Aktiv</c:if></td> not work, where the problem lies?

  • This makes no sense. See the duplicate for a basic explanation on how stuff is supposed to work. JavaScript has its own `if ()` statement already. Make use of it. – BalusC Sep 26 '16 at 06:39

1 Answers1

0

I hope you are using this code in jsp. In js JSTL tag will not work. Below correction in your code should solve the problem.

  $.each(jsondata.data,function(i,obj){
            var status = obj.sts;
            tableHtml ="<tr> <td>"+ obj.id_mobile + "</td> <td>" + obj.nama +"</td> <td>"+ obj.username +"</td> <td>"
            + obj.kota + "</td> <td>";
<c:if test="${status == 1}">
  tableHtml+="Aktiv";
</c:if>
tableHtml+="</td><td align='center'><button type='button' class='btn tom-history' title='History' ></button></td> </tr>";
            $(tableHtml).appendTo('#datatable tbody');
        }); 
Vijendra Kumar Kulhade
  • 2,217
  • 3
  • 15
  • 25