Francesco
Francesco

Reputation: 199

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 calls start correctly but the server queued the requests and execute jsut one per time.

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. The first one ajax request response after 5 seconds, the second one after 10 and so on. But everyone starts asyncronusly and correctly with a difference of few milliseconds

Upvotes: 1

Views: 2111

Answers (1)

jeroen
jeroen

Reputation: 91734

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.

Just use session_write_close(); as soon as you have what you need from the session.

Upvotes: 1

Related Questions