• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with passing values to bootstrap modal window

#1
Sad 
I am just start creating a database update system with a bootstrap modal window. I am using ajax to populate the modal form fields but not getting any value. Please review the code and help me to figure out the error.

 HTML Code
Code:
<!-- Modal -->
        <div class="modal fade" id="edit_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">Edit Data</h4>
                  </div>
                  <div class="modal-body">
                      <div class="content-wrapper content-wrapper--with-bg">
                      <?php echo form_open('quotation'); ?>
                           <p>
                            <input type="text" name="bname" id="bname" required class="form-control custom-ctrl" placeholder="Billing Name">
                           </p>  
                           <span class="text-danger"><?php echo form_error('bname'); ?></span>
                           <p>
                            <input type="text" name="company" id="company" required class="form-control custom-ctrl" placeholder="Company">
                           </p>
                           <span class="text-danger"><?php echo form_error('company'); ?></span>
                            <input type="hidden" name="id" id="id"> 
                            </p>
                            <button type="submit" id="update" class="btn btn-primary btn-custom pull-right"> Update</button>
                            <br>
                        <?php echo form_close(); ?>
              </div>
            </div>
          </div>
        </div>
      </div>

My Controller

PHP Code:
public function fetch_by_id(){
    $this->load->model("quotation_model");
    $result $this->quotation_model->fetch_by_id();
    echo json_encode($result);   


And Here is the Modal associated with the controller.


PHP Code:
public function fetch_by_id(){
    $id $this->input->get('id');
    $this->db->where('id'$id);
    $query $this->db->get('quotes');
    return $query->result();


Here is the ajax code
Code:
$(document).on('click', '.editBtn', function(){
   var id = $(this).attr('data');
   $('#edit_modal').modal('show');

   $.ajax({
       type: 'ajax',
       method: 'get',
       url: '<?php echo base_url(); ?>quotation/fetch_by_id',
       data: {id: id},
       async: false,
       dataType: 'json',
       success: function(data){
          $("input[name=id]").val(data.id);
          $("input[name=bname]").val(data.bname);
          $("input[name=company]").val(data.company);
       },
       error: function(){
           alert('Could not displaying data');
       },
   });
});

I am just able to popup the modal window but not getting any value
Reply

#2
Try to see if this tutorial can help you:

https://www.codexworld.com/codeigniter-c...uery-ajax/
Reply

#3
I do not recommend having two functions/methods with the same name, your just asking for trouble.
Rename one of them to a different name.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#4
(02-06-2019, 10:24 AM)InsiteFX Wrote: I do not recommend having two functions/methods with the same name, your just asking for trouble.
Rename one of them to a different name.
But this is not the problem in my case...right?
Reply

#5
The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.
Reply

#6
(02-06-2019, 11:47 AM)skunkbad Wrote: The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.
@skunkbad please check again, i have forgot to include the ajax
Reply

#7
(02-06-2019, 12:45 PM)shamiul72 Wrote:
(02-06-2019, 11:47 AM)skunkbad Wrote: The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.
@skunkbad please check again, i have forgot to include the ajax

You must specify a content-type header for JSON:


PHP Code:
header('Content-Type: application/json'); 
Reply

#8
(02-06-2019, 02:12 PM)skunkbad Wrote:
(02-06-2019, 12:45 PM)shamiul72 Wrote:
(02-06-2019, 11:47 AM)skunkbad Wrote: The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.
@skunkbad please check again, i have forgot to include the ajax

You must specify a content-type header for JSON:


PHP Code:
header('Content-Type: application/json'); 
No Luck still facing the empty fields  Sad
Reply

#9
Here is an example on how to do it in CodeIgniter with Ajax.

View data in a Bootstrap modal using Ajax, jQuery and PHP
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#10
Here is an example.

jQuery AJAX Example
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.