weixin_33728708 2016-09-26 03:49 采纳率: 0%
浏览 71

AJAX中的JSTL无法正常工作

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/6957832/how-to-add-el-code-or-jstl-code-through-javascript" dir="ltr">how to add el code or jstl code through javascript</a>
                            <span class="question-originals-answer-count">
                                (3 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2016-09-26 06:38:55Z" class="relativetime">3 years ago</span>.</div>
        </div>
    </aside>

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?

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33726318 2016-09-26 03:54
    关注

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

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊