dth8312 2015-12-01 08:54
浏览 104
已采纳

第一个AJAX调用花了太多时间等待

My first AJAX request (manual or using jQuery's load, get, post, ajax) takes too much time (50+ seconds). Following AJAX requests becomes normal.

When I troubleshoot the problem using Network section of Chrome and Firefox it showed that it takes almost 51 seconds in waiting (attached is the screenshot). Why is this taking so much time? I am clueless that for which thing the request is waiting for. Here is my code

$(function() {
    $('#frmPrd').live('submit', function(event) {
        event.preventDefault();
        mUrl = "page1.php";
        $.ajax({
            url: mUrl,
            type: 'POST',
            data: $("#frmPrd").serialize(),
            success: function() {
                //Following request is taking 50+ seconds.
                $("#dvCart").load("page.php");
            },
            error: function() {
                alert('Error occurred.');
            }  
        });
    });
});

The screeshot of Network section Waiting for what?

I already have asked the question (following link) but still the issue is not solved. jQuery simple load taking too much time for first call

  • 写回答

1条回答 默认 最新

  • douxing8323 2015-12-01 09:04
    关注

    The wait time depends entirely upon your server (and in some cases on your network connection). This is the time from when the request was sent by the client until it first starts receiving the response. Assuming you're not on a really slow network connection or one with really bad latency (like a satellite link), this is pretty much all about how long it takes the server to respond to the request.

    If only the very first ajax call is this slow, then there is probably some sort of "startup" time on the server. If this is a busy server or overloaded server, then it could be that your app is swapped out of memory or the cache is empty and it takes a longer time to get your app up and running and ready to start processing the response. This might be more common in a shared hosting environment when there are many other active applications sharing the same resources and your server has not been recently active.

    Since this looks like a PHP server, it could be that the PHP engine used by the web server has some startup time or the web server has to load something before it can start processing PHP requests and that initialization takes a bunch of time. Or, it could be as simple as a hard drive on the server had been powered down and it has to spin up to speed before things can start processing.

    It will take instrumenting and profiling on the server to find out exactly which possible issue is the main cause of the server-side delay.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化