Welcome Guest, Not a member yet? Register   Sign In
Access ajax data from the function and use it outside CI3
#5

Hi. You can get results from your get_row controller method and display the result in another view file. For example,

Code:
Controller:

public function get_towns_of_a_city(){
        $city_id = $this->request->getVar('city_id');
        $data['towns'] = $this->YourModel->get_towns_of_a_city($city_id);

      echo view('site-view/data-area/towns-result', $data);
    }


Then you can use it after any Ajax call. For example,

Code:
<script type="text/javascript">
    $(document).ready(function(){
        $('#city-select').change(function(){
            let city_id = $(this).val();

            $.ajax({
            url:"<?php echo base_url('SiteController/get_towns_of_a_city');?>",
            method:'POST',
            data:{city_id:city_id},
            success: function(data){
                $('#towns').html(data);
            },
            error: function(data){
            console.log('there is an error somewhere');
          }
   
            });//ajax ends */
               
        });
    });
</script>


You can add another js/ajax in that towns-result view and also anything else.

Hope this was the thing you need.
Reply


Messages In This Thread
RE: Access ajax data from the function and use it outside CI3 - by demyr - 04-24-2023, 02:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB