[英]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.我正在处理 PHP CodeIgniter。通过单击客户名称,我调用 JavaScript function
customerBasic
用于其他目的,也调用show_cs_info
,发送 AJAX 调用至 controller,如下所示。
AJAX function: 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: 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 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 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. AJAX 通话耗时 1.05 秒。 How can I make it faster?
我怎样才能让它更快?
实际上,如果数据库服务器在另一台服务器上,您需要检查网络连接并尝试消除网络延迟..... 在其他情况下,如果您在本地服务器上工作并且在同一台机器上有 web 和数据库服务器,然后检查 CPU 使用率和MySQL 上的工作负载可能因某些查询而卡住……进一步升级您的服务器和 MySQL 版本等……
You are executing an ajax post request without any data.您正在执行没有任何数据的 ajax 发布请求。 Post requests are intended to cause a server reaction and thus are slower.
发布请求旨在引起服务器反应,因此速度较慢。 So setting
type
to 'get' will speed up your request somewhat.因此,将
type
设置为 'get' 会稍微加快您的请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.