小编jan*_*on0的帖子

为什么我的Ajax调用中的"等待"长度如此之长?(Chrome网络面板)

我在一个请求一些json内容的页面上有几个ajax调用.在所有这些电话中,我在响应完成时获得了大量的等待时间.对于这些呼叫中的每一个,呼叫都会有几秒钟的"等待"时间,如下面的"Chrome网络"面板中所示.我附上了一张照片:

等待Ajax Call  - 截屏1

我不确定是什么导致了这一点,因为我对查询数据库的php代码进行了一些基准测试,并据此调用查询和处理json发回的调用在0.001秒左右运行.

那么,这只是网络延迟吗?这是一个我没有正确进行数据库查询的问题吗?也许我充斥着每个浏览器窗口的最大连接数?不知道.其他请求的移动速度一样慢,所以看起来它可能是一致的.

这是其余请求计时的另一张照片(其他主要的ajax调用与get_usergames_simple调用的时间一样多: 所有要求

作为参考,这里是ajax调用:

self.getGamesContent = function()
{
  var userID = "<?php echo $userID; ?>";

  var post_data = {
    userID: userID
  };

  $.post("https://mydomain.com/games/get_usergames_simple/", post_data, function(result)
  {
    var json = $.parseJSON(result);

    var mappedGames = $.map(json.games, function(item) {
      return new GameItem(item)
    });
    self.gameitems(mappedGames);
  });
};
Run Code Online (Sandbox Code Playgroud)

这是运行查询的控制器中的php代码:

$userID = $this->input->post('userID');
$this->benchmark->mark('code_start');

$userGames = $this->cache->model('games', 'getGamesSimpleByUserID', array($userID), 120); // keep for 2 minutes

$returnString = "{";

$returnString .= '"user_id": "' . $userID . '",';

$gameCount = 0;

$returnString .= '"games": [';
foreach ($userGames …
Run Code Online (Sandbox Code Playgroud)

ajax jquery codeigniter knockout.js

5
推荐指数
1
解决办法
1998
查看次数

标签 统计

ajax ×1

codeigniter ×1

jquery ×1

knockout.js ×1