簡體   English   中英

多次Ajax函數調用導致加載緩慢

[英]Multiple Ajax function calls cause slow to load

    function function1(val)
    {
       $.ajax({
         type: 'post',
         url: 'page1.php',
         data: {
           get_option:val
         },
         success: function (response) {
           document.getElementById("id1").value=response; 
           function2(val);
           function3(val);
           function4(val);
           function5(val);
         }
       });
    }

function function2(val)
    {
       $.ajax({
         type: 'post',
         url: 'page2.php',
         data: {
           get_option:val
         },
         success: function (response) {
           document.getElementById("id2").value=response; 
           function6(val);

         }
       });
    }

function function3(val)
    {
       $.ajax({
         type: 'post',
         url: 'page3.php',
         data: {
           get_option:val
         },
         success: function (response) {
           document.getElementById("id3").value=response; 

         }
       });
    }

這是我的一些功能function1成功的部分,我稱其他功能為function2,function3,function4,function5。 在我的第二個函數function2中,我在成功的部分調用了另一個函數function6,這花費了更多的時間來獲取結果
如何避免這種等待時間...?

如果每個ajax請求都按順序返回結果,則可能是會話阻塞有效。 如果可以同時執行腳本而不影響結果,請嘗試在PHP代碼的早期添加以下內容:

session_write_close();  //let the next requests start

這將允許隨后的ajax請求開始PHP處理,並應顯着改善您的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM