skip to Main Content

I have a website that uses the eBay API to load everything into eBay and everything else.

The main files are PHP that are just included into one file that calls the scripts when needed.

But what I am after now is creating a simple website that will be split down the middle one half contains the links to the scripts and the other a plain empty div that loads the contents from the PHP files and displays this in the empty div.

As the php files are mostly run on loops and can run for as long as 5 minutes I would like the script to echo out what it has done in the empty div.

At the minute I am using

while (@ob_end_flush());      
ob_implicit_flush(true);   

so the PHP scripts output the echo’s before the end of the file, but when using:

function loadScript() {
    $(".loading").load("load.php");
    Loaddelay = setTimeout('loadScript()',1000);
}
loadScript();

In the main index file that re-loads the file every 1 seconds and shows nothing. as the script cannot actually run.

What other options do i have of dynamically changing the div container so it contains the running PHP script?

2

Answers


  1. Chosen as BEST ANSWER

    in the end I realised that I actually didn't need to use jQuery to load the page like I was doing.

    I just ended up using an iframe that was placed within the div.

    <a onclick="loadThis('page.php')">Do some thing</a>
    
    <script type="text/javascript">
    function loadThis(file) {
        $("myiframe").attr("src", file");
    }
    </script>
    

    it works fine, and better then expected. cannot believe I overlooked using an iframe.


  2. If the information is not confidential or sensitive, one thing you could do is pipe the output of the script that takes time to execute to a file and read that file from your page using jQuery.load().

    So you would :

    1. Define a session variable that both the server and your page’s JavaScript know (this will define the file name that the content will be outputed to)
    2. Start the execution of the long PHP script with a jQuery.ajax()
    3. Read the file (which the name is defined earlier) at predefined intervals like you are doing in your current script
    4. When your long script end, write some special characte at the end of your file so that you stop the reading of the file from the client

    Note that you would need to refine the way you define the session variables if the user was to execute multiple pages at the same time

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search