Java script ajax call

  1. We have to write onclick function in HTML tag
  2. Here we need to pass user id through php
  3. we need to create js function and inside we should write ajax call and pass the controller function names

ex :-

1 Html tag  

<div class="btn-group"><button type="button" onclick="functioin_name('<?php echo $clientleads->acc_id;?>', <?php echo $stage_row['0']['stage_id'];?>)"> </button

2 Js function

function function_name($varible1 , varible2){

$('#ws_status_id').val(acc_id);

            $('#form_stage_id').val(stage_id);

                     $.ajax({

                url: '<?php echo base_url();?>Clients/get_stage_name', // controller name/ function name

                type: 'POST',

                data: {

                    stage_id: varibel1 //pass the variables or id

                },

                success: function (response) {

                    console.log(response);

                    var stage_ids = JSON.parse(response);

                    var stage_name = stage_ids.stages;

                    $("#stage_name").html(stage_name); // model class input field name

                   

                }

            });

3 Codeigniter controller function

 public function get_stage_name()

          {

            extract($_POST);

            $stage_name =  "select * from table_name where condition"; // your query and conditions

            echo json_encode($stage_name);

          }

Tagged:
Sign In or Register to comment.