'Very slow AJAX response

I am working on PHP CodeIgniter. By clicking on customer name I call a JavaScript function customerBasic for some other purpose that also call show_cs_info that send AJAX call to controller as below.

AJAX function:

function customerBasic(customer_id,isConsumer, name )
 {
   document.getElementById('random').value = customer_id+"/"+name;
   $.ajax({
        url: site_url+"customer/connections/index/"+customer_id+"/"+0+"/"+isConsumer,
        type: 'post',
        success: function(data)
        { 

           show_cs_info(customer_id);
        }
     });

}

show_cs_info function:

function show_cs_info(id)
{
  $.ajax({
     url:site_url+"customer/customer/show_cs_info"+"/"+id+"/"+'no',
     type:'post',
     success:function(data)
     {
        $('#right_div').html(data);
     }
});
}

controller

 public function show_cs_info($id, $bit)
 {
    $id = urldecode($id);
    $bit = urldecode($bit);
    $this->load->model('customer_model');
    $data['val']= $this->customer_model->show_cs_info($id);
    $this->load->view('show_cust_info_view',$data);
 }

Model

 public function show_cs_info($id)
 {
        $this->db->where('customer_id',$id);
        $result = $this->db->get('customer_info');
        return $result->result();
 }

The AJAX call is taking 1.05s. How can I make it faster?



Solution 1:[1]

Actually you need to check network connection if Database server is on another server and try to remove network latency..... In other-case if you are working on local server and have web & DB server on same machine then check CPU Usage and Workload on MySQL it may be stuck due to some query...... Further upgrade your server & version of MySQL etc....

Solution 2:[2]

You are executing an ajax post request without any data. Post requests are intended to cause a server reaction and thus are slower. So setting type to 'get' will speed up your request somewhat.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Umair Aziz
Solution 2 Meneer Venus