Cara manggil function di href di ajax

Saya dapat masalah saat manggil function href di ajax saat mau menampilkan notify.js

Ini Codingnya:

View

  <tbody>
                                            <?php foreach ($rows as $row) { ?>
					    <tr>
                                                <td><?php echo $row ->description ?></td>
						<td><?php echo $row->updated_at ?></td>
                                                <td><a href="<?php echo base_url().'admin/edittipe/'.$row->id ?>">Edit</a></td>
                                                <td><a id="aDeleteOrderType" onclick="type_delete()" href="#.<?php echo $row->id ?>">Delete</a></td>
                                            </tr>
                                            <?php } ?>
                                        </tbody>

Admin Footer

 <script>
    $("#aDeleteOrderType").click(function(e){
        e.preventDefault();
        $.ajax({
          url: '<?php echo base_url().'admin/type_delete' ?>',
          type: 'post',
          data: {

          },
          success: function(msg)
          {
              if (msg == 'valid')

            {

                $.notify('Data Has Been Deleted', 'error')
            }

          }

    });

});

</script>

Function di Controller

 public function type_delete($id)
        {
            $is_logged_in1 = $this->session->userdata('is_logged_in');
            $type = $this->session->userdata('type');
            if(!isset($is_logged_in1) || $is_logged_in1 != true)
        {
            $data['error'] = '';
            $this->load->view('login-1', $data);
        }
        else
        {
            $this->load->model('listtipeorder_model');
            $this->listtipeorder_model->delete_list_type($id);
            echo 'valid';
        }
        }
avatar rafaelhrhp
@rafaelhrhp

4 Kontribusi 0 Poin

Diperbarui 6 tahun yang lalu

1 Jawaban:

cek

<pre> &lt;a id="aDeleteOrderType" onclick="type_delete()" href="#.&lt;?php echo $row-&gt;id ?&gt;"&gt;Delete&lt;/a&gt; </pre>

ganti jadi

<pre>&lt;a href="javascript:void(0);" data-id="&lt;?php echo $row-&gt;id ?&gt;" id="aDeleteOrderType"&gt;Delete&lt;/a&gt;</pre>

Admin Footer Benerin Jquery action nya, contoh buat ngambil data id nya

<pre> &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#aDeleteOrderType').click(function() { /* Act on the event */ var id = $(this).attr("data-id"); alert(id); }); });
&lt;/script&gt;

</pre>

kalo data id nya udah dapet tinggal kirim pake ajax ke action controllernya :) semoga membantu

avatar AsrulMaa
@AsrulMaa

23 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban