V
V
Vladimir Singhtlov2014-03-18 16:18:48
JavaScript
Vladimir Singhtlov, 2014-03-18 16:18:48

What is the error when sending an AJAX request to Codeigniter?

AJAX

$( document ).ready(function(){  
        $('#clinics li a').click(checkService($(this).attr('value')));
    });

    function checkService(id_clinic){
      $.ajax({
    url: host + "appointments/checkService",
    async: true,
    type: 'POST',
                dataType: 'json',
    data: {id_clinic : id_clinic},
    success: function(data){
                    $('#result').html(data);
                }
            });
    };

database query
public function  listServiceOfClinics($id){
        if(!$id){
  return false;
        }
        return  $this->db->select('t_services.s_id,t_services.s_name')->from('t_services')->join('t_listserviceofclinics','t_services.s_id = t_listserviceofclinics.s_id_services')->where(['s_id_clinic'=>$id])->get()->result_array();
    }

Controller
public function checkService(){
             $id_services = $this->model_appointments->listServiceOfClinics($this->input->post('id_clinic'));
             print json_encode($id_services);
         }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-03-18
Protko @Fesor

So what is the error?
If the data comes from the server normally, then I think you have an error in the line:
you have json coming from the server, so data will contain a json object and you need to stuff it into a template first.

V
Vladimir Singhtlov, 2014-03-18
@singhtless

that's what the jamb was

$id_clinic = $this->input->post('id_clinic');
             $id_services = $this->model_appointments->listServiceOfClinics($id_clinic);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question