简体   繁体   English

如何从同一客户端向同一页面执行多个HTTP请求

[英]How to execute multiple HTTP Request to the same page from the same client

I want to run some AJAX calls at the same page from the same client. 我想在同一客户端的同一页面上运行一些AJAX调用。 Ajax calls start correctly but the server queued the requests and execute jsut one per time. Ajax调用正确启动,但是服务器将请求排队,并每次执行一次jsut。

I've also check the start request time and the returned message time. 我还检查了启动请求时间和返回的消息时间。 Studying the second one there's a difference between the requests which is multiple than the before request. 研究第二个请求,请求之间的差异比之前的请求多。

Help me please! 请帮帮我!

$("document").ready(function() { 
    $(".user-id").each(function() { 
        var id = $(this).html(); 
        getData(id); 
    }); 
}); 
function getData(id) { 
    $.ajax({ 
            url: 'loadOperatorDiagram.php', 
            type: 'GET', 
            data: {id: id}, 
            async: true, 
            cache: false, 
            success: function(resp) { 
                 $("#boxes").append(resp); 
                 draw(id); // A javascript function which draw into a canvas
             } 
    }); 
} 

loadOperatorDiagram.php get some queries and its execution time is about 5 seconds. loadOperatorDiagram.php得到一些查询,其执行时间约为5秒。 The first one ajax request response after 5 seconds, the second one after 10 and so on. 第一个ajax请求在5秒后响应,第二个在10秒后响应,依此类推。 But everyone starts asyncronusly and correctly with a difference of few milliseconds 但是每个人都能以几毫秒的时间正确地异步启动

If you are using sessions in php (sounds like it, otherwise you could do at least 2 simultaneous requests...), you should close it as soon as possible in your php script as php will block the session. 如果您正在php中使用会话(听起来很像,否则您可以同时执行至少2个请求...),则应在php脚本中尽快将其关闭,因为php会阻止会话。

Just use session_write_close(); 只需使用session_write_close(); as soon as you have what you need from the session. 会话中有您需要的内容时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM