how using foreach in ajax codeigniter

Question

Dear Expert need help how to add foreach between variable tbaris :

function show_infouser(Kode)
   { save_method = 'update';
       $('#form')[0].reset(); // reset form on modals
       $('.form-group').removeClass('has-error'); // clear error class
       $('.help-block').empty(); // clear error string
       $.ajax({url : "<?php echo site_url('infouser/ajax_user')?>/" + Kode,
       type: "GET",
       dataType: "JSON",
       success: function(data){
         if (data == null)
         { showConfirmButton: false }); }
         else {
// want to show foreach in here
           var tbaris = '<tr><td style="width:3px; font-size:11px;"><center>'+data.No+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+data.Name+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+data.Job+'</center></td>';
           tbaris += '<td style="width:3px; font-size:11px;"><center>'+data.Status+'</center></td>';
           $('#tableuser tbody').html(tbaris);
           $('#modal_form1').modal('show');
           $('.modal-title').text('SHOW ROOM');}},
          error: function (jqXHR, textStatus, errorThrown)
               {
                   alert('Error get data from ajax' + errorThrown);
                   alert('Error get data from ajax' + textStatus);
                   alert('Error get data from ajax' + jqXHR);
               }
           });
       }

Show source
| arrays   | ajax   | codeigniter   2017-01-03 09:01 1 Answers

Answers to how using foreach in ajax codeigniter ( 1 )

  1. 2017-01-03 09:01

    Try as below using $.each()...

     function show_infouser(Kode)
           { 
               save_method = 'update';
               $('#form')[0].reset(); // reset form on modals
               $('.form-group').removeClass('has-error'); // clear error class
               $('.help-block').empty(); // clear error string
    
               $.ajax({
               url : "<?php echo base_url('infouser/ajax_user');?>/" + Kode,
               type: "GET",
               dataType: "JSON",
               success: function(response){
                 if (response == null)
                 { showConfirmButton: false } 
                 else {
    // want to show foreach in here
                var tbaris ='';
                $.each(response,function(index) {
                tbaris += '<tr><td style="width:3px; font-size:11px;"><center>'+response[index].No+'</center></td>';
               tbaris += '<td style="width:3px; font-size:11px;"><center>'+response[index].Name+'</center></td>';
               tbaris += '<td style="width:3px; font-size:11px;"><center>'+response[index].Job+'</center></td>';
               tbaris += '<td style="width:3px; font-size:11px;"><center>'+response[index].Status+'</center></td>';
               }
               $('#tableuser tbody').html(tbaris);
               $('#modal_form1').modal('show');
               $('.modal-title').text('SHOW ROOM');
                 }
             },
              error: function (jqXHR, textStatus, errorThrown)
                   {
                       alert('Error get data from ajax' + errorThrown);
                       alert('Error get data from ajax' + textStatus);
                       alert('Error get data from ajax' + jqXHR);
                   }
               });
           }
    

Leave a reply to - how using foreach in ajax codeigniter

◀ Go back