4

I've got 2 ajax requests on one page. I ran first request and separately start second one. But second one stops working after the first has been run. And continue when first is over. First requst take long time - something like 30 - 60 seconds and in this time I need second request to show logs what happens with first request. I try to use async: true but it's not help me.

Here it's my code

<script type="text/javascript">
    var auto_refresh = setInterval( function()
        { asyncGet('log.php') }, 1000
    );

    function asyncGet(addr) {
        $.ajax({
            url: addr,
            async: true,
            success: function (response) {
                $('#loadLog').html(response);
            }
        });
    }

    function getConn(addr) {
        $.ajax({
            url: addr,
            async: true,
            success: function (response) {
                stopGet();
            }
        });
    }


</script>

<div id="loadLog" class="lLog"></div>

and I call first ajax request in this way: getConn('main.php'); from function when press button. Second request it's running, but not show respons before first request complete.

I wil attach image from firebug. main.php - is request that take longer time. log.php - is the logger that is blocked.

enter image description here

Would really appreciate some pointers to where I'm going wrong

2
  • stackoverflow.com/questions/561046/… Commented Aug 22, 2012 at 9:44
  • Yes :) If main.php is not running - log is loading very fast every second. Here is the code: <?php require 'config.php'; isLogged(); $log = run_q("SELECT * FROM logs WHERE user_id = $logged[id] AND revision = $logged[revision] ORDER BY id DESC"); while ($r = mysql_fetch_assoc($log)) { echo '&nbsp; => ' . $r['event'] . ' ' . $r['date'] . '<br />'; } ?> Commented Aug 22, 2012 at 9:48

1 Answer 1

8

This may be a problem with session. Check out this post. Suppose you may need to close session in your main.php as fast as possible.

Sign up to request clarification or add additional context in comments.

4 Comments

I just had one of those “Awwwwuuuu” moments. I honestly in 6 years of PHP never knew this. Thanks a lot :)
Hey, I have similar problem but I am not using session. session is used as global but not for the functions that are invoked. I use database to retrieve results. Please help.
@JunaidAtique it is not required for your code to use session directly . It might be started on each request automatically even if it is not needed.
@FAngel thanks I figured that out. I was using session as global. Now I have made it to controller specific. Thanks for you time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.