0

Since we have our new server we have some issues with calling multiple jquery posts.

On some pages we call multiple jquery posts like this:

$.ajax({
    type: "POST",
    url: "../files/processed/includes/process.php",
    data: $('#myform').serialize(),
    complete: function(data)
    {
        $('#results').html(data.responseText);
    }
});

$.ajax({
    type: "POST",
    url: "../files/processed/includes/folders.php",
    data: '',
    complete: function(data)
    {
        $('#getFolders').html(data.responseText);
    }
});

The last post always wait for the first one. On our old server this was no problem and both posts loaded at te same time.

With a small change I speeded up a little but not as fast when used our old server. Strange thing is that the resources on our new server are much better.

The change I mentioned is:

$.ajax({
        type: "POST",
        url: "../files/processed/includes/process.php",
        data: $('#myform').serialize(),
        complete: function(data)
        {
            $('#results').html(data.responseText);

            $.ajax({
                type: "POST",
                url: "../files/processed/includes/folders.php",
                data: '',
                complete: function(data)
                {
                    $('#getFolders').html(data.responseText);
                }
            });
        }
    });

Is there another fix to load both posts at the same time or at least to speed it up?

Leon van der Veen
  • 1,652
  • 11
  • 42
  • 60

1 Answers1

5

On the server perform session_write_close() as soon as you don't need to modify session data.

Otherwise the second request waits until the first one holds the session file locked. And the lock is released after the first request ends.

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • Thanks for your reply but I'm not sure how to use your solution. Do I have to use session_write_close() in process.php? – Leon van der Veen Nov 23 '12 at 11:17
  • @Leon van der Veen: in the server side script you're sending your request to. In this case it's `process.php` or any other file it includes. – zerkms Nov 23 '12 at 11:18
  • at the bottom of the page or in the top? – Leon van der Veen Nov 23 '12 at 11:18
  • 1
    @Leon van der Veen: "as soon as you don't need to modify session data.". The far from the top - the longer script holds the lock. Please read my answer once again, and documentation for the function as well: http://php.net/session_write_close – zerkms Nov 23 '12 at 11:19
  • @Leon van der Veen: what was slow? Your original question was about: "The last post always wait for the first one" - and I've answered to that. – zerkms Nov 23 '12 at 11:24
  • The last post is still loads very slow. – Leon van der Veen Nov 23 '12 at 11:46
  • @Leon van der Veen: and how speed of loading is relevant? Your script works slow - so profile it and find why. It's not related to client side – zerkms Nov 24 '12 at 00:32