vendredi 30 novembre 2018

Using statement if in looping ajax

Maybe friends here consider me not doing my own business, or googling research. But I am asking a question here because indeed I feel deadlocked, which is why this forum is said to be stack overflow.

I want to use a statement on data looping done on ajax, but I have a problem.

Error:

Uncaught SyntaxError: Unexpected token if

The syntax below is what I made, if this is indeed wrong please help me fix it.

      $.ajax({
        type: 'get',
        url : '<?php echo base_url() ?>index.php/truk/daftar_jeniskerusakan_ajx',
        dataType: 'JSON',
        success:function(data){
          var i = 1;
          var html;
          for (x=0; x<data.length;x++) {
            html += "<tr>"+
                    "<td>"+i+"</td>"+
                    "<td>"+data[x].jenis_kerusakan+"</td>"+
                    if(data[x].status === "1"){
                    "<td>"+"&nbsp;"+"</td>"+
                    }else{                          
                    "<td>"+"<a href='' class='btn btn-xs btn-success'>Approve</a>"+"</td>"+
                    };
                    "</tr>";
                  i++;
          }
          $('#daftar_jenis_kerusakan').append(html);
          $('#daftar_jenis_kerusakan').DataTable({
            "pageLength" : 10,
            "dom" : '<"search"f><"top">rt<"bottom"ip><"clear">'
          });
        }
      });

Aucun commentaire:

Enregistrer un commentaire