2016-09-26 101 views
-1

需要你help.I想写像阿贾克斯<C:IF>一些JSTL代码,但它合乎理不行JSTL在AJAX不起作用

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

}); 

}

这段代码<td><c:if test="${status == 1}">Aktiv</c:if></td>不行, 其中问题在哪里?

+0

这是没有意义的。有关如何工作的基本解释,请参阅重复内容。 JavaScript有它自己的'if()'语句。利用它。 – BalusC

回答

0

我希望你在jsp中使用这段代码。在JS JSTL标签将无法正常工作。 在您的代码中进行下面的更正应该可以解决问题。

$.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

我已经实现你的代码,但仍然没有工作,所以我改成if(状态== 1){ \t \t \t tableHtml + =“Aktiv”; \t \t} –

+0

哎呀,这是一个愚蠢的答案。我没有看到你的json响应中的状态。抱歉 –