2016-09-26 11 views
-1

benötigen help.I einige JSTL Code wie <C:IF> in Ajax schreiben wollen, aber es doestJSTL in AJAX funktioniert nicht

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'); 
     }); 
    } 

}); 

}

diesen Code <td><c:if test="${status == 1}">Aktiv</c:if></td> nicht funktioniert, nicht funktionieren , wo die Problem liegt?

+0

Das macht keinen Sinn. Sehen Sie das Duplikat für eine grundlegende Erklärung, wie das Zeug funktionieren soll. JavaScript hat bereits eine eigene 'if()' Anweisung. Nutze es. – BalusC

Antwort

0

Ich hoffe, Sie verwenden diesen Code in JSP. In js JSTL-Tag wird nicht funktionieren. Unterhalb der Korrektur in Ihrem Code sollte das Problem lösen.

$.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'); 
     }); 
+0

Ich habe Ihren Code implementiert aber immer noch nicht funktioniert, also ändere ich in if (status == 1) { \t \t \t tableHtml + = "Aktiv"; \t \t} –

+0

Hoppla, das war eine dumme Antwort. Ich habe nicht gesehen, dass dieser Status in Ihrer JSON-Antwort vorhanden ist. Es tut uns leid –