Note that there are some explanatory texts on larger screens.

plurals
  1. POalert if success update using ajax in codeigniter
    primarykey
    data
    text
    <p>Help me please. I'm new in ajax. I'm using codeigniter.. I'm using a javascript modal (alert) to show if i successfully deleted a data. </p> <p>here is my view:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).on("click", ".delete-data", function () { var id = $(this).data('id'); $("#id").val( id ); }); &lt;/script&gt; &lt;div class="down1"&gt; &lt;button type="button" class="button-orange" onclick="add_child();" id="child_add"&gt;Add&lt;/button&gt; &lt;/div&gt; &lt;div class="span11 offset1" id="childdv"&gt; &lt;?php echo $child_set;?&gt; &lt;!--this one shows that table of children--&gt; &lt;/div&gt; the modal delete &lt;!--delete--&gt; &lt;div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-haspopup="true" aria-hidden="true"&gt; &lt;div class="modal-dialog"&gt; &lt;div class="modal-content"&gt; &lt;div class="alert alert-danger fade in" id="alert"&gt; &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt; &lt;h3&gt;Heads Up!&lt;/h3&gt; &lt;p&gt;What you are doing will delete a data!&lt;/p&gt; &lt;input type="hidden" name="id" id="id" value=""/&gt; &lt;a onclick="delete_child();" id="okButton" class="btn btn-danger" data-dismiss="modal"&gt; Confirm Delete &lt;/a&gt; &lt;a href="#" class="btn" data-dismiss="modal"&gt; Cancel &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>my main controller that shows the </p> <pre><code>$data_set['record_set'] = $this-&gt;emp-&gt;get_children($id); $data['employee_header_menus'] = $this-&gt;load-&gt;view('employee_header_menus', NULL, TRUE); $data['employee_header_logout'] = $this-&gt;load-&gt;view('employee_header_logout', NULL, TRUE); $data['child_set'] = $this-&gt;load-&gt;view('swoosh_template/employee/child', $data_set, TRUE); //&lt;--- you can see in here that the $child_set came from here. $data['info'] = $this-&gt;emp-&gt;get_myinfo($id); $data['msg'] = ""; $data['color'] = "green"; $data['header_logo'] = $this-&gt;load-&gt;view('header_logo', NULL, TRUE); $this-&gt;load-&gt;view('employee/personaldetails', $data); </code></pre> <p>now. where is that child_set . it is a view. </p> <pre><code>&lt;?php if ($record_set !="" ) { ?&gt; &lt;table id="tblcount" class="table table-bordered"&gt; &lt;tr class="orange"&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Date of Birth&lt;/th&gt; &lt;th&gt;Dependent&lt;/th&gt; &lt;th&gt;Delete&lt;/th&gt; &lt;/tr&gt; &lt;?php foreach ($record_set as $row): ?&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo $row[ 'name'];?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo $row[ 'birth_date'];?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($row[ 'dependent']=='1' ? 'Yes': 'No');?&gt; &lt;/td&gt; &lt;td&gt; &lt;img data-toggle="modal" data-id="&lt;?php echo $row['id']?&gt;" class="delete-data" href="#delete" style="cursor:pointer" height="15" width="15" src="&lt;?php echo base_url(); ?&gt;images/remove.gif"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach?&gt; &lt;/table&gt; </code></pre> <p>here is my javascript that calls the modal.</p> <pre><code>function delete_child() { var id = $("#id").val(); if (id!=null){ swoosh(id, path+'swoosh_employee/swoosh_delete_child', 'childdv'); //&lt;-- this is the function that calls my controller $('#success').modal('show'); // &lt;-- this is the alert. } } </code></pre> <p>but I don't want to put the alert there. cause i want to validate first if my function in my controller runs successfully. and that's the time that I will show that alert.</p> <p>here is my controller:</p> <pre><code>public function swoosh_delete_child() { $P1 = $this-&gt;session-&gt;userdata('id'); parse_str($_SERVER['QUERY_STRING'],$_GET); $id = $_GET['h']; $this-&gt;emp-&gt;delete_children($id); // &lt;-- in here , i want to validate this. if successful: alert success, else alert error $set['record_set'] = $this-&gt;emp-&gt;get_children($P1); $this-&gt;load-&gt;view('swoosh_template/employee/child',$set); } </code></pre> <p>here is the model:</p> <pre><code>public function delete_children($P1) { $this-&gt;db-&gt;delete('employee_children', array('ID' =&gt; $P1)); } </code></pre> <p>now . what I want to do is . "ajax".. that will check if the function runs successfully or if i deleted successfully like:</p> <pre><code>if success{ $('#success').modal('show'); } else{ $('#error').modal('show'); } </code></pre> <p>I've been searching on how to use ajax. but i can't seem to understand it.. I'm just new in programming. Average.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload