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

  • Home
  • SEARCH
  • 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 8883931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:56:21+00:00 2026-06-14T20:56:21+00:00

Consider an AJAX call that writes to a div: recent_req=$.post(‘result.php’, { d: data },

  • 0

Consider an AJAX call that writes to a div:

recent_req=$.post('result.php', { d: data }, function(returnData) {
    $('#content').html(returnData);
});

The PHP script at result.php performs some functions that take time, about 5-20 seconds per step. I am using PHP’s flush() function to get the info to the browser as soon as each step starts and ends, but how can I get the Javascript to write the data to the #content div as it comes in?

Thanks.

EDIT:
To clarify: Assume result.php looks like the following and due to constraints cannot be practically refactored:

<?php

echo "Starting...<br />";
flush();

longOperation();
echo "Done with first long operation.<br />";
flush();

anotherLongOperation();
echo "Done with another long operation.<br />";
flush();

?>

How might the AJAX be structured to call result.php such that the echo statements are appended to the #content div as they come in? Any solution with / without jQuery is welcome. Thanks!

  • 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-06-14T20:56:22+00:00Added an answer on June 14, 2026 at 8:56 pm

    There’s a technique using an iframe which you could use to achieve this.

    Similar to other suggestions involving frames but it doesn’t involve sessions or polling or anything, and doesn’t need you to display the iframe itself. It also has the benefit of running any code you want at any point in the process, in case you’re doing something more sophisticated with your UI than just pushing text to a div (e.g. you could update a progress bar).

    Basically, submit the form to a hidden iFrame then flush javascript to that frame, which interacts with functions in the iFrame’s parent.

    Like this:

    HTML:

    <form target="results" action="result.php" method="post">
    <!-- your form -->
    <input type="submit" value="Go" />
    </form>
    
    <iframe name="results" id="results" width="0" height="0" />
    <div id="progress"></div>
    

    Javascript, in your main page:

    function updateProgress(progress) {
      $("#progress").append("<div>" + progress + "</div>");
    }
    

    result.php:

    <?php
    
    echo "<script language='javascript'>parent.updateProgress('Starting...');</script>";
    flush();
    
    longOperation();
    echo "<script language='javascript'>parent.updateProgress('Done with first long operation.');</script>";
    flush();
    
    anotherLongOperation();
    echo "<script language='javascript'>parent.updateProgress('Done with another long operation.');</script>";
    flush();
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following AJAX call to load RSS news data on click event: $(function()
Consider: function ajaxCall(url, callback) { $.ajax({ type: GET, url: url, success: function (data) {
Consider the following Mechanize form object #<Mechanize::Form {name f1} {method POST} {action f.php} {fields
Is there any provisions in rails that would allow all AJAX POST requests from
Consider the following code: var x = 0; do { $.ajax({ type: POST, url:
Consider the following scenario: http://www.restserver.com/example.php returns some content that I want to work with
I don't understand how to use the XUI xhr (ajax) call. Consider the following
Consider that you want to add an ajax functionality to many links on your
Consider the following form containing textfield and submit button: <form method=POST action=<?php isValid();?> class=urln>
i have seen that ajaxStart/ajaxStop always used against a DIV . Consider the following:

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.