ajax - use foreach loop in json format in codeigniter -


i want loop table in json,

my return value is

array( [0]array( [m_id]=>2 [event_id]=>37 [activity_id]=>20 ) [1]array( [m_id]=>20 [event_id]=>3 [activity_id]=>2 ) ) 

my script is

function get_out_mail(user_name){                                            var datastring = 'user_name=' + user_name;                     alert(datastring);                     var = false;                     $.ajax({                             type: "post",                             async: false,                             url: "<?php echo site_url(); ?>admin/get_out_mails",                             data: datastring,                             cache: false,                             success: function (result) {                                 alert(result);                                 var result = $.parsejson(result);                                 console.log(result.from);                                 $('#mytable').html('');                                 $("#mytable").append('<tbody><?php foreach ($get_all_mail $get_all_mails) { ?><tr id="target-list"><td><input type="checkbox" id="mail-checkbox-1" class="custom-checkbox"></td><input type="hidden" name="mid" value="<?php echo $get_all_mails['m_id']; ?>"/><td><i class="glyph-icon icon-star"></i></td><td class="email-title" ><?php echo $get_all_mails['from']; ?></td><td class="email-body" ><?php echo $get_all_mails['subject'] ?></td><td><i class="glyph-icon icon-paperclip"></i></td><td>17 jan 2014</td></tr><?php } ?></tbody>');                             }                         });                         return a;                     } 

my controller

public function get_out_mails(){     if ($this->session->userdata('admin_logged_in')) {         $user_name = $this->input->post('user_name');         $result['out_mail'] = $this->admin_model->get_out_mailss($user_name);         print_r($result['out_mail']); } 

here want append return array value in json using foreach loop, how can this.

it ajax request better return complete html part in controller instead of appending in view page :

example controller :

echo $values ="<body>          <tr> test</tr>    </body>";  view : success :  function(data){      $('#id').html(data); } 

with hide complete loop view page , code in controller


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -