Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:48:59+00:00 2026-05-27T23:48:59+00:00

I am using jQuery to call a function when a button is clicked. This

  • 0

I am using jQuery to call a function when a button is clicked. This function that is being called is in PHP and returns logging information. I have tried to use setInterval() but it calls the function at whatever rate I choose and tends to return duplicate logging information and most of the time it freezes. Is there a way that I can make repeated calls to a PHP function from jQuery, but only call the function after the last call is finished and returned?

Here is the jQuery code that makes involves the setInterval()

setInterval(
            function(){
                $.getJSON("ajax.php?function=tail&pointer=" + ftell,
                    function(data){
                        var obj = [];
                        obj = $.parseJSON(data); 

                        ftell = obj[0];
                        $("#tail").append(obj[1]);
                    });
            }, 2000);

Here is the PHP function that it calls

function tail(){
    $file = "/path/to/the/log/file.log";
    $handle = fopen($file, "r");
    clearstatcache();

    $currentSize = filesize($file);            
    $offset = $_REQUEST['pointer'] - $currentSize;

    if ($_REQUEST['pointer'] == 0) {
        fseek($handle, -1024, SEEK_END);
    } else {
        fseek($handle, $_REQUEST['pointer'], SEEK_END);
    }

    while ($buffer = fgets($handle)) { 
        $log .= $buffer . "<br />";
    } 

    fclose($handle);      
    $results = array('0' => $currentSize, '1' => str_replace('"', '\"', $log));     
    echo json_encode($results);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:49:00+00:00Added an answer on May 27, 2026 at 11:49 pm

    This will trigger another ajax event five seconds after the first one has finished. It wont matter whether it’s succeeded or failed.

    function checkForUpdates() {
      var delay = 5000; //in milliseconds, so 5s
      setTimeout(function () {
        $.ajax(...).always(checkForUpdates);
      }, delay);
    }
    

    Some concerns with writing code like this can be that it doesn’t contain a mechanism for cancelling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a slideshow using jQuery I have a button called
I am using jQuery and JavaScript, I need to call the jQuery function inside
I am using jQuery. I call a JavaScript function with next html: <li><span><a href=javascript:uncheckEl('tagVO-$id')>$tagname</a></span></li>
I am using the below jquery code to call a ajax function in my
I'm trying to call a Page Method using a jQuery 'attached' event function, in
I am using the $.ajax function in jquery to make a call to an
I am loading feed-items into a ul using this jQuery .ajax() call, which I
I am trying to call a jquery function on clicking a button in the
I have a question form that I want to validate using jquery. My form
I have a form using jquery validation plugin. My submit button has an ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.